Class: DoubleEntry::Account

Inherits:
Object
  • Object
show all
Defined in:
lib/double_entry/account.rb

Defined Under Namespace

Classes: ActiveRecordScopeFactory, Instance, Set

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Account

Returns a new instance of Account.



150
151
152
153
154
155
156
157
158
159
160
# File 'lib/double_entry/account.rb', line 150

def initialize(args)
  @identifier = args[:identifier]
  @scope_identifier = args[:scope_identifier]
  @positive_only = args[:positive_only]
  @negative_only = args[:negative_only]
  @currency = args[:currency] || Money.default_currency
  if identifier.length > Account.
    fail AccountIdentifierTooLongError,
         "account identifier '#{identifier}' is too long. Please limit it to #{Account.} characters."
  end
end

Class Attribute Details

.account_identifier_max_lengthObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



18
19
20
# File 'lib/double_entry/account.rb', line 18

def 
  @account_identifier_max_length ||= 31
end

.accountsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



8
9
10
# File 'lib/double_entry/account.rb', line 8

def accounts
  @accounts ||= Set.new
end

.scope_identifier_max_lengthObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



13
14
15
# File 'lib/double_entry/account.rb', line 13

def scope_identifier_max_length
  @scope_identifier_max_length ||= 23
end

Instance Attribute Details

#currencyObject (readonly)

Returns the value of attribute currency.



148
149
150
# File 'lib/double_entry/account.rb', line 148

def currency
  @currency
end

#identifierObject (readonly)

Returns the value of attribute identifier.



148
149
150
# File 'lib/double_entry/account.rb', line 148

def identifier
  @identifier
end

#negative_onlyObject (readonly)

Returns the value of attribute negative_only.



148
149
150
# File 'lib/double_entry/account.rb', line 148

def negative_only
  @negative_only
end

#positive_onlyObject (readonly)

Returns the value of attribute positive_only.



148
149
150
# File 'lib/double_entry/account.rb', line 148

def positive_only
  @positive_only
end

#scope_identifierObject (readonly)

Returns the value of attribute scope_identifier.



148
149
150
# File 'lib/double_entry/account.rb', line 148

def scope_identifier
  @scope_identifier
end

Class Method Details

.account(identifier, options = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



23
24
25
26
# File 'lib/double_entry/account.rb', line 23

def (identifier, options = {})
   = accounts.find(identifier, options[:scope].present?)
  Instance.new(:account => , :scope => options[:scope])
end

.currency(identifier) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def currency(identifier)
  accounts.detect { |a| a.identifier == identifier }.try(:currency)
end

Instance Method Details

#scoped?Boolean

Returns:

  • (Boolean)


162
163
164
# File 'lib/double_entry/account.rb', line 162

def scoped?
  !!scope_identifier
end