Class: Rivendell::Import::Cart
- Inherits:
-
Object
- Object
- Rivendell::Import::Cart
- Includes:
- ActiveModel::Serialization, ActiveModel::Serializers::JSON
- Defined in:
- lib/rivendell/import/cart.rb
Defined Under Namespace
Classes: ApiUpdater, DbUpdater, Updater
Instance Attribute Summary collapse
-
#album ⇒ Object
Returns the value of attribute album.
-
#artist ⇒ Object
Returns the value of attribute artist.
-
#clear_cuts ⇒ Object
(also: #clear_cuts?)
Returns the value of attribute clear_cuts.
-
#default_title ⇒ Object
Returns the value of attribute default_title.
-
#group ⇒ Object
Returns the value of attribute group.
-
#import_options ⇒ Object
Returns the value of attribute import_options.
-
#number ⇒ Object
Returns the value of attribute number.
-
#scheduler_codes ⇒ Object
Returns the value of attribute scheduler_codes.
-
#task ⇒ Object
readonly
Returns the value of attribute task.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
- #attributes ⇒ Object
- #attributes=(attributes) ⇒ Object
- #cart_finder ⇒ Object
- #clear_cuts! ⇒ Object
- #create ⇒ Object
- #cut ⇒ Object
- #find_by_title(string, options = {}) ⇒ Object
- #import(file) ⇒ Object
-
#initialize(task = nil) ⇒ Cart
constructor
A new instance of Cart.
- #update ⇒ Object
- #updaters ⇒ Object
- #xport ⇒ Object
Constructor Details
#initialize(task = nil) ⇒ Cart
Returns a new instance of Cart.
38 39 40 |
# File 'lib/rivendell/import/cart.rb', line 38 def initialize(task = nil) @task = task end |
Instance Attribute Details
#album ⇒ Object
Returns the value of attribute album.
35 36 37 |
# File 'lib/rivendell/import/cart.rb', line 35 def album @album end |
#artist ⇒ Object
Returns the value of attribute artist.
35 36 37 |
# File 'lib/rivendell/import/cart.rb', line 35 def artist @artist end |
#clear_cuts ⇒ Object Also known as: clear_cuts?
Returns the value of attribute clear_cuts.
187 188 189 |
# File 'lib/rivendell/import/cart.rb', line 187 def clear_cuts @clear_cuts end |
#default_title ⇒ Object
Returns the value of attribute default_title.
35 36 37 |
# File 'lib/rivendell/import/cart.rb', line 35 def default_title @default_title end |
#group ⇒ Object
Returns the value of attribute group.
35 36 37 |
# File 'lib/rivendell/import/cart.rb', line 35 def group @group end |
#import_options ⇒ Object
Returns the value of attribute import_options.
159 160 161 |
# File 'lib/rivendell/import/cart.rb', line 159 def end |
#number ⇒ Object
Returns the value of attribute number.
35 36 37 |
# File 'lib/rivendell/import/cart.rb', line 35 def number @number end |
#scheduler_codes ⇒ Object
Returns the value of attribute scheduler_codes.
35 36 37 |
# File 'lib/rivendell/import/cart.rb', line 35 def scheduler_codes @scheduler_codes end |
#task ⇒ Object (readonly)
Returns the value of attribute task.
36 37 38 |
# File 'lib/rivendell/import/cart.rb', line 36 def task @task end |
#title ⇒ Object
Returns the value of attribute title.
35 36 37 |
# File 'lib/rivendell/import/cart.rb', line 35 def title @title end |
Instance Method Details
#as_json(options = {}) ⇒ Object
7 8 9 |
# File 'lib/rivendell/import/cart.rb', line 7 def as_json( = {}) super .merge(:root => false) end |
#attributes ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rivendell/import/cart.rb', line 11 def attributes attributes = {} %w{number group clear_cuts title default_title scheduler_codes artist album import_options}.each do |attribute| value = send attribute attributes[attribute] = value if value.present? end if (cut_attributes = cut.attributes).present? attributes["cut"] = cut_attributes end attributes end |
#attributes=(attributes) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/rivendell/import/cart.rb', line 23 def attributes=(attributes) attributes.each do |k,v| unless k == "cut" send "#{k}=", v else cut.attributes = v end end end |
#cart_finder ⇒ Object
194 195 196 197 198 199 200 201 |
# File 'lib/rivendell/import/cart.rb', line 194 def cart_finder @cart_finder ||= unless Database.enabled? Rivendell::Import::CartFinder::ByApi.new xport else Rivendell::Import::CartFinder::ByDb.new end end |
#clear_cuts! ⇒ Object
190 191 192 |
# File 'lib/rivendell/import/cart.rb', line 190 def clear_cuts! self.clear_cuts = true end |
#create ⇒ Object
50 51 52 53 54 55 |
# File 'lib/rivendell/import/cart.rb', line 50 def create unless number raise "Can't create Cart, Group isn't defined" unless group.present? self.number = xport.add_cart(:group => group).number end end |
#cut ⇒ Object
155 156 157 |
# File 'lib/rivendell/import/cart.rb', line 155 def cut @cut ||= Cut.new(self) end |
#find_by_title(string, options = {}) ⇒ Object
178 179 180 181 182 183 184 185 |
# File 'lib/rivendell/import/cart.rb', line 178 def find_by_title(string, = {}) Rivendell::Import.logger.debug "Looking for a Cart '#{string}'" if remote_cart = cart_finder.find_by_title(string, ) Rivendell::Import.logger.debug "Found Cart #{remote_cart.number}" self.number = remote_cart.number self.[:use_metadata] = false end end |
#import(file) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/rivendell/import/cart.rb', line 164 def import(file) raise "File #{file.path} not found" unless file.exists? if clear_cuts? Rivendell::Import.logger.debug "Clear cuts of Cart #{number}" xport.clear_cuts number end cut.create Rivendell::Import.logger.debug "Import #{file.path} in Cut #{cut.number}" xport.import number, cut.number, file.path, .symbolize_keys cut.update end |
#update ⇒ Object
57 58 59 60 61 |
# File 'lib/rivendell/import/cart.rb', line 57 def update updaters.any? do |updater| updater.new(self).update end end |
#updaters ⇒ Object
63 64 65 66 67 68 |
# File 'lib/rivendell/import/cart.rb', line 63 def updaters [].tap do |updaters| updaters << ApiUpdater if scheduler_codes.empty? updaters << DbUpdater if Database.enabled? end end |
#xport ⇒ Object
46 47 48 |
# File 'lib/rivendell/import/cart.rb', line 46 def xport task.xport end |