Class: Rivendell::Import::Cut
- Inherits:
-
Object
- Object
- Rivendell::Import::Cut
- Includes:
- ActiveModel::Serialization, ActiveModel::Serializers::JSON
- Defined in:
- lib/rivendell/import/cut.rb
Instance Attribute Summary collapse
-
#cart ⇒ Object
readonly
Returns the value of attribute cart.
-
#datetime ⇒ Object
Returns the value of attribute datetime.
-
#daypart ⇒ Object
Returns the value of attribute daypart.
-
#days ⇒ Object
Returns the value of attribute days.
-
#description ⇒ Object
Returns the value of attribute description.
-
#isci ⇒ Object
Returns the value of attribute isci.
-
#isrc ⇒ Object
Returns the value of attribute isrc.
-
#number ⇒ Object
Returns the value of attribute number.
-
#outcue ⇒ Object
Returns the value of attribute outcue.
Instance Method Summary collapse
- #api_attributes ⇒ Object
- #api_attributes? ⇒ Boolean
- #as_json(options = {}) ⇒ Object
- #attributes ⇒ Object
- #attributes=(attributes) ⇒ Object
- #create ⇒ Object
- #db_attributes? ⇒ Boolean
-
#initialize(cart) ⇒ Cut
constructor
A new instance of Cut.
- #name ⇒ Object
- #update ⇒ Object
- #xport ⇒ Object
Constructor Details
#initialize(cart) ⇒ Cut
Returns a new instance of Cut.
16 17 18 |
# File 'lib/rivendell/import/cut.rb', line 16 def initialize(cart) @cart = cart end |
Instance Attribute Details
#cart ⇒ Object (readonly)
Returns the value of attribute cart.
7 8 9 |
# File 'lib/rivendell/import/cut.rb', line 7 def cart @cart end |
#datetime ⇒ Object
Returns the value of attribute datetime.
12 13 14 |
# File 'lib/rivendell/import/cut.rb', line 12 def datetime @datetime end |
#daypart ⇒ Object
Returns the value of attribute daypart.
13 14 15 |
# File 'lib/rivendell/import/cut.rb', line 13 def daypart @daypart end |
#days ⇒ Object
Returns the value of attribute days.
14 15 16 |
# File 'lib/rivendell/import/cut.rb', line 14 def days @days end |
#description ⇒ Object
Returns the value of attribute description.
10 11 12 |
# File 'lib/rivendell/import/cut.rb', line 10 def description @description end |
#isci ⇒ Object
Returns the value of attribute isci.
10 11 12 |
# File 'lib/rivendell/import/cut.rb', line 10 def isci @isci end |
#isrc ⇒ Object
Returns the value of attribute isrc.
10 11 12 |
# File 'lib/rivendell/import/cut.rb', line 10 def isrc @isrc end |
#number ⇒ Object
Returns the value of attribute number.
9 10 11 |
# File 'lib/rivendell/import/cut.rb', line 9 def number @number end |
#outcue ⇒ Object
Returns the value of attribute outcue.
10 11 12 |
# File 'lib/rivendell/import/cut.rb', line 10 def outcue @outcue end |
Instance Method Details
#api_attributes ⇒ Object
53 54 55 |
# File 'lib/rivendell/import/cut.rb', line 53 def api_attributes attributes.extract!("description", "outcue", "isrc", "isci").delete_if { |_,v| v.blank? } end |
#api_attributes? ⇒ Boolean
57 58 59 |
# File 'lib/rivendell/import/cut.rb', line 57 def api_attributes? api_attributes.present? end |
#as_json(options = {}) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/rivendell/import/cut.rb', line 20 def as_json( = {}) super(.merge(:root => false)).tap do |as_json| as_json.each do |k,v| as_json[k] = [v.begin, v.end] if v.is_a?(Range) end end end |
#attributes ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/rivendell/import/cut.rb', line 28 def attributes %w{description outcue isrc isci datetime daypart days}.inject({}) do |map, attribute| value = send attribute map[attribute] = value if value map end end |
#attributes=(attributes) ⇒ Object
36 37 38 |
# File 'lib/rivendell/import/cut.rb', line 36 def attributes=(attributes) attributes.each { |k,v| send "#{k}=", v } end |
#create ⇒ Object
44 45 46 47 |
# File 'lib/rivendell/import/cut.rb', line 44 def create Rivendell::Import.logger.debug "Create Cut for Cart #{cart.number}" self.number = xport.add_cut(cart.number).number unless number end |
#db_attributes? ⇒ Boolean
61 62 63 |
# File 'lib/rivendell/import/cut.rb', line 61 def db_attributes? [datetime, daypart, days].any? &:present? end |
#name ⇒ Object
49 50 51 |
# File 'lib/rivendell/import/cut.rb', line 49 def name "%06d_%03d" % [cart.number, number] end |
#update ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/rivendell/import/cut.rb', line 65 def update if db_attributes? Rivendell::Import.logger.debug "Save Cut db attributes #{inspect}" Database.init db_cut = Rivendell::DB::Cut.get(name) if datetime db_cut.start_datetime, db_cut.end_datetime = datetime.begin, datetime.end end if daypart db_cut.start_daypart, db_cut.end_daypart = daypart.begin, daypart.end end if days db_cut.days = days end Rivendell::Import.logger.debug "Change Cut #{number} in DB #{db_cut.inspect}" db_cut.save end if api_attributes? Rivendell::Import.logger.debug "Change Cut #{number} via API #{api_attributes.inspect}" xport.edit_cut cart.number, number, api_attributes end end |
#xport ⇒ Object
40 41 42 |
# File 'lib/rivendell/import/cut.rb', line 40 def xport cart.xport end |