Class: Clearbooks::Journal

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

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

build, create

Constructor Details

#initialize(data) ⇒ Journal

Returns a new instance of Journal.

Parameters:



46
47
48
49
50
51
52
# File 'lib/clearbooks/model/journal.rb', line 46

def initialize data
  @description = data.savon :description
  @accounting_date = parse_date data.savon :accounting_date
  @entity = data.savon :entity
  @project = data.savon :project
  @ledgers = Ledger.build data.savon :ledgers
end

Instance Attribute Details

#accounting_dateObject (readonly)

Optional. The accounting date of the journal. return [Date]



21
22
23
# File 'lib/clearbooks/model/journal.rb', line 21

def accounting_date
  @accounting_date
end

#descriptionObject (readonly)

Required. The description of the journal. return [String]



16
17
18
# File 'lib/clearbooks/model/journal.rb', line 16

def description
  @description
end

#entityObject (readonly)

Optional. The ID of an entity attached to the journal. return [Fixnum]



26
27
28
# File 'lib/clearbooks/model/journal.rb', line 26

def entity
  @entity
end

#ledgersObject (readonly)

Optional. An array of transactions added to the journal. Two items required. return [Array, Ledger]



36
37
38
# File 'lib/clearbooks/model/journal.rb', line 36

def ledgers
  @ledgers
end

#projectObject (readonly)

Optional. The ID of a project attached to the journal. return [Fixnum]



31
32
33
# File 'lib/clearbooks/model/journal.rb', line 31

def project
  @project
end

Instance Method Details

#to_savonHash

Returns self as Savon readable Hash

Returns:

  • (Hash)

    Returns self as Savon readable Hash



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/clearbooks/model/journal.rb', line 58

def to_savon
  {
    journal: {
      :@description => @description,
      :@accountingDate => @accounting_date.strftime('%F'),
      :@entity => @entity,
      :@project => @project,
      :ledgers => @ledgers.map(&:to_savon)
    }.compact
  }
end