Class: Base4R::UniversalItem

Inherits:
Item
  • Object
show all
Defined in:
lib/item.rb

Overview

Item with a minimal set of Attributes, extend for specific Item Types

Direct Known Subclasses

ProductItem

Instance Attribute Summary

Attributes inherited from Item

#attributes, #base_id, #draft, #title, #unique_id

Instance Method Summary collapse

Methods inherited from Item

#draft?, #options_from_value, #to_xml

Methods included from ItemAttributeMethods

included

Constructor Details

#initialize(*args) ⇒ UniversalItem

Create a new UniversalItem, with unique_id, created by author_name who’s email is author_email, described by description, found at URL link, entitled title, phone number is contact_phone, item type is item_type, target_country e.g. ‘GB’, item_language e.g. ‘EN’

Args can also be a hash of attributes



216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/item.rb', line 216

def initialize(*args)
  options = initialize_args_to_options(args)
  #allow an option to specify which columns are private
  private_attributes = [options.delete(:private_attributes)].flatten.inject([]){|list, val| list << val.to_s if val; list}.uniq

  @title        = options.delete(:title)
  self.draft    = options.delete(:draft)
  @attributes = []

  options.each do |key, value|
    v = options_from_value(value, :private_attribute => private_attributes.include?(key.to_s))
    #back support for author name and email
    if value && [:author_name, :author_email].include?(key.to_sym)
      send "#{key}=", value
    else
      add_attribute key, v
    end
  end
end