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.
152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/double_entry/account.rb', line 152 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 raise AccountIdentifierTooLongError.new( "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.
19 20 21 |
# File 'lib/double_entry/account.rb', line 19 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.
9 10 11 |
# File 'lib/double_entry/account.rb', line 9 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.
14 15 16 |
# File 'lib/double_entry/account.rb', line 14 def scope_identifier_max_length @scope_identifier_max_length ||= 23 end |
Instance Attribute Details
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
150 151 152 |
# File 'lib/double_entry/account.rb', line 150 def currency @currency end |
#identifier ⇒ Object (readonly)
Returns the value of attribute identifier.
150 151 152 |
# File 'lib/double_entry/account.rb', line 150 def identifier @identifier end |
#negative_only ⇒ Object (readonly)
Returns the value of attribute negative_only.
150 151 152 |
# File 'lib/double_entry/account.rb', line 150 def negative_only @negative_only end |
#positive_only ⇒ Object (readonly)
Returns the value of attribute positive_only.
150 151 152 |
# File 'lib/double_entry/account.rb', line 150 def positive_only @positive_only end |
#scope_identifier ⇒ Object (readonly)
Returns the value of attribute scope_identifier.
150 151 152 |
# File 'lib/double_entry/account.rb', line 150 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.
24 25 26 27 |
# File 'lib/double_entry/account.rb', line 24 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.
30 31 32 |
# File 'lib/double_entry/account.rb', line 30 def currency(identifier) accounts.detect { |a| a.identifier == identifier }.try(:currency) end |
Instance Method Details
#scoped? ⇒ Boolean
165 166 167 |
# File 'lib/double_entry/account.rb', line 165 def scoped? !!scope_identifier end |