Class: DoubleEntry::Account
- Inherits:
-
Object
- Object
- DoubleEntry::Account
- Defined in:
- lib/double_entry/account.rb
Defined Under Namespace
Classes: ActiveRecordScopeFactory, Instance, Set
Class Attribute Summary collapse
- .account_identifier_max_length ⇒ Object private
- .accounts ⇒ Object private
- .scope_identifier_max_length ⇒ Object private
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
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.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
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 @account_identifier_max_length ||= 31 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.
8 9 10 |
# File 'lib/double_entry/account.rb', line 8 def accounts @accounts ||= Set.new end |
.scope_identifier_max_length ⇒ 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.
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
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
148 149 150 |
# File 'lib/double_entry/account.rb', line 148 def currency @currency end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
148 149 150 |
# File 'lib/double_entry/account.rb', line 148 def identifier @identifier end |
#negative_only ⇒ Object (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_only ⇒ Object (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_identifier ⇒ Object (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 account(identifier, = {}) account = accounts.find(identifier, [:scope].present?) Instance.new(:account => account, :scope => [: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
162 163 164 |
# File 'lib/double_entry/account.rb', line 162 def scoped? !!scope_identifier end |