Class: Collector::ArticleListItem

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/collector/article_list_item.rb

Instance Method Summary collapse

Methods inherited from BaseModel

#==, #all_attributes, attribute, attribute_opt, attributes, #attributes, attributes_opt, #attributes_opt, #has_required_attributes?, #missing_attributes, #missing_attributes_human_readable, #nested_missing, #own_missing, swallow_unsupported_attributes, swallow_unsupported_attributes?, #validate_input

Constructor Details

#initialize(hash_or_invoice_row = {}) ⇒ ArticleListItem

Returns a new instance of ArticleListItem.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/collector/article_list_item.rb', line 5

def initialize(hash_or_invoice_row = {})
  if hash_or_invoice_row.kind_of? Hash
    super(hash_or_invoice_row)
  elsif hash_or_invoice_row.kind_of? InvoiceRow
    hash = attributes.inject({}) do |memo, attr|
      memo[attr] = hash_or_invoice_row.send(attr)
      memo
    end
    super(hash)
  else
    raise ArgumentError.new("An ArticleListItem must be initialized with a hash or an InvoiceRow instance.")
  end
end