Class: DoubleEntry::Account

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

Defined Under Namespace

Classes: Instance, Set

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Account



143
144
145
146
147
148
149
150
151
152
153
# File 'lib/double_entry/account.rb', line 143

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 Account. && 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

Returns the value of attribute account_identifier_max_length.



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

def 
  @account_identifier_max_length
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.



11
12
13
# File 'lib/double_entry/account.rb', line 11

def accounts
  @accounts ||= Set.new
end

.scope_identifier_max_lengthObject

Returns the value of attribute scope_identifier_max_length.



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

def scope_identifier_max_length
  @scope_identifier_max_length
end

Instance Attribute Details

#currencyObject (readonly)

Returns the value of attribute currency.



141
142
143
# File 'lib/double_entry/account.rb', line 141

def currency
  @currency
end

#identifierObject (readonly)

Returns the value of attribute identifier.



141
142
143
# File 'lib/double_entry/account.rb', line 141

def identifier
  @identifier
end

#negative_onlyObject (readonly)

Returns the value of attribute negative_only.



141
142
143
# File 'lib/double_entry/account.rb', line 141

def negative_only
  @negative_only
end

#positive_onlyObject (readonly)

Returns the value of attribute positive_only.



141
142
143
# File 'lib/double_entry/account.rb', line 141

def positive_only
  @positive_only
end

#scope_identifierObject (readonly)

Returns the value of attribute scope_identifier.



141
142
143
# File 'lib/double_entry/account.rb', line 141

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.



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

def (identifier, options = {})
   = accounts.find(identifier, (options[:scope].present? || options[:scope_identity].present?))
  Instance.new(account: , scope: options[:scope], scope_identity: options[:scope_identity])
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.



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

def currency(identifier)
  accounts.find_without_scope(identifier).try(:currency)
end

Instance Method Details

#scoped?Boolean



155
156
157
# File 'lib/double_entry/account.rb', line 155

def scoped?
  !!scope_identifier
end