Class: DoubleEntry::Account
- Inherits:
-
Object
- Object
- DoubleEntry::Account
- Defined in:
- lib/double_entry/account.rb
Defined Under Namespace
Class Attribute Summary collapse
-
.account_identifier_max_length ⇒ Object
Returns the value of attribute account_identifier_max_length.
- .accounts ⇒ Object private
-
.scope_identifier_max_length ⇒ Object
Returns the value of attribute scope_identifier_max_length.
Instance Attribute Summary collapse
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#identifier ⇒ Object
readonly
Returns the value of attribute identifier.
-
#negative_only ⇒ Object
readonly
Returns the value of attribute negative_only.
-
#positive_only ⇒ Object
readonly
Returns the value of attribute positive_only.
-
#scope_identifier ⇒ Object
readonly
Returns the value of attribute scope_identifier.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(args) ⇒ Account
constructor
A new instance of Account.
- #scoped? ⇒ Boolean
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.account_identifier_max_length && identifier.length > Account.account_identifier_max_length fail AccountIdentifierTooLongError, "account identifier '#{identifier}' is too long. Please limit it to #{Account.account_identifier_max_length} characters." end end |
Class Attribute Details
.account_identifier_max_length ⇒ Object
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 @account_identifier_max_length end |
.accounts ⇒ 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.
11 12 13 |
# File 'lib/double_entry/account.rb', line 11 def accounts @accounts ||= Set.new end |
.scope_identifier_max_length ⇒ Object
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
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
141 142 143 |
# File 'lib/double_entry/account.rb', line 141 def currency @currency end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
141 142 143 |
# File 'lib/double_entry/account.rb', line 141 def identifier @identifier end |
#negative_only ⇒ Object (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_only ⇒ Object (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_identifier ⇒ Object (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 account(identifier, = {}) account = accounts.find(identifier, ([:scope].present? || [:scope_identity].present?)) Instance.new(account: account, scope: [:scope], scope_identity: [: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 |