Class: Subledger::Domain::Account

Direct Known Subclasses

ActiveAccount, ArchivedAccount

Defined Under Namespace

Classes: Entity

Instance Attribute Summary collapse

Attributes included from Roles::Versionable

#version

Attributes included from Roles::Storable

#client, #store

Attributes included from Roles::Identifiable

#id

Attributes included from Roles::Describable

#description, #reference

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Roles::Restable

#patch_hash, #post_hash, #serializable_hash, #to_json

Methods included from Roles::Archivable

#archive

Methods included from Roles::Activatable

#activate

Methods included from Roles::Collectable

included

Methods included from Roles::Updatable

included, #update

Methods included from Roles::Readable

included, #read

Methods included from Roles::Creatable

#create, included

Methods included from Roles::Versionable

included

Methods included from Roles::Attributable

#attributes

Methods included from Subledger::Domain

#==, #collection_name, #entity_name, included, #to_s

Constructor Details

#initialize(args) ⇒ Account

Returns a new instance of Account.



68
69
70
71
72
73
74
75
76
# File 'lib/subledger/domain/account.rb', line 68

def initialize args
  describable args
  identifiable args
  storable args
  versionable args

  @book           = args[:book]
  @normal_balance = args[:normal_balance]
end

Instance Attribute Details

#bookObject (readonly)

Returns the value of attribute book.



26
27
28
# File 'lib/subledger/domain/account.rb', line 26

def book
  @book
end

#normal_balanceObject

Returns the value of attribute normal_balance.



27
28
29
# File 'lib/subledger/domain/account.rb', line 27

def normal_balance
  @normal_balance
end

Class Method Details

.active_klassObject



45
46
47
# File 'lib/subledger/domain/account.rb', line 45

def self.active_klass
  ActiveAccount
end

.archived_klassObject



49
50
51
# File 'lib/subledger/domain/account.rb', line 49

def self.archived_klass
  ArchivedAccount
end

.first_and_last_line(args) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/subledger/domain/account.rb', line 53

def self.first_and_last_line args
  store  = args[:store]
  client = args[:client]

  id = args[:id]

  if id.nil?
    raise AccountError, 'cannot get first and last lines without an :id'
  end

  args.merge! :account => client.accounts( :id => id )

  store.first_and_last_line args
end

.patch_keysObject



33
34
35
# File 'lib/subledger/domain/account.rb', line 33

def self.patch_keys
  [ :id, :description, :reference, :normal_balance, :version ]
end

.post_keysObject



29
30
31
# File 'lib/subledger/domain/account.rb', line 29

def self.post_keys
  [ :description, :reference, :normal_balance ]
end

.root_klassObject



37
38
39
# File 'lib/subledger/domain/account.rb', line 37

def self.root_klass
  Account
end

.sub_klassesObject



41
42
43
# File 'lib/subledger/domain/account.rb', line 41

def self.sub_klasses
  [ active_klass, archived_klass ]
end

Instance Method Details

#balance(args) ⇒ Object



91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/subledger/domain/account.rb', line 91

def balance args
  at = args[:at]

  unless at.kind_of? Time
    raise AccountError, ':at must be a Time'
  end

  store. :store   => store,
                        :client  => client,
                        :account => self,
                        :at      => at.utc
end

#first_and_last_lineObject



104
105
106
# File 'lib/subledger/domain/account.rb', line 104

def first_and_last_line
  client.accounts.first_and_last_line :id => self.id
end

#line(args) ⇒ Object



78
79
80
# File 'lib/subledger/domain/account.rb', line 78

def line args
  client.posted_lines( args.merge! :account => self )
end

#lines(args = { }, &block) ⇒ Object



82
83
84
85
86
87
88
89
# File 'lib/subledger/domain/account.rb', line 82

def lines args={ }, &block
  args.merge! :action       => args[:action]       || :ending,
              :state        => args[:state]        || :posted,
              :effective_at => args[:effective_at] || Time.now.utc,
              :account      => self

  client..collect args, &block
end