Class: Clearbooks::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/clearbooks/model/base.rb

Direct Known Subclasses

AccountCode, Entity, Invoice, Item, Journal, Ledger, Payment, Project

Class Method Summary collapse

Class Method Details

.build(data) ⇒ Array

Note:

Still returns an array when called with a hash representing a single item.

Returns List of items that represent collection from hash returned by Savon.

Parameters:

  • data (Array)

    An array of hashes representing collection or a hash representing a single item

Returns:

  • (Array)

    List of items that represent collection from hash returned by Savon



22
23
24
25
26
27
28
29
30
# File 'lib/clearbooks/model/base.rb', line 22

def build data
  if data.nil?
    Array.new
  elsif data.is_a? Array
    data.map { |d| create(d) }
  else
    [ create(data) ]
  end
end

.create(data) ⇒ Object

Returns An item instantiated from a hash returned by Savon.

Parameters:

  • data (Hash)

    Hash representing a single object returned by Savon

Returns:

  • (Object)

    An item instantiated from a hash returned by Savon



38
39
40
41
42
43
44
# File 'lib/clearbooks/model/base.rb', line 38

def create data
  if data.is_a? Hash
    new data
  else
    data
  end
end