Class: DoubleEntry::Account::Instance
- Inherits:
-
Object
- Object
- DoubleEntry::Account::Instance
- Includes:
- Comparable
- Defined in:
- lib/double_entry/account.rb
Instance Attribute Summary collapse
-
#account ⇒ Object
readonly
Returns the value of attribute account.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
-
#balance(options = {}) ⇒ Money
Get the current or historic balance of this account.
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(args) ⇒ Instance
constructor
A new instance of Instance.
- #inspect ⇒ Object
- #scope_identity ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(args) ⇒ Instance
Returns a new instance of Instance.
84 85 86 87 88 |
# File 'lib/double_entry/account.rb', line 84 def initialize(args) @account = args[:account] @scope = args[:scope] ensure_scope_is_valid end |
Instance Attribute Details
#account ⇒ Object (readonly)
Returns the value of attribute account.
81 82 83 |
# File 'lib/double_entry/account.rb', line 81 def account @account end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
81 82 83 |
# File 'lib/double_entry/account.rb', line 81 def scope @scope end |
Instance Method Details
#<=>(other) ⇒ Object
117 118 119 |
# File 'lib/double_entry/account.rb', line 117 def <=>(other) [scope_identity.to_s, identifier.to_s] <=> [other.scope_identity.to_s, other.identifier.to_s] end |
#==(other) ⇒ Object
109 110 111 |
# File 'lib/double_entry/account.rb', line 109 def ==(other) other.is_a?(self.class) && identifier == other.identifier && scope_identity == other.scope_identity end |
#balance(options = {}) ⇒ Money
Get the current or historic balance of this account.
103 104 105 |
# File 'lib/double_entry/account.rb', line 103 def balance( = {}) BalanceCalculator.calculate(self, ) end |
#eql?(other) ⇒ Boolean
113 114 115 |
# File 'lib/double_entry/account.rb', line 113 def eql?(other) self == other end |
#hash ⇒ Object
121 122 123 124 125 126 127 |
# File 'lib/double_entry/account.rb', line 121 def hash if scoped? "#{scope_identity}:#{identifier}".hash else identifier.hash end end |
#inspect ⇒ Object
133 134 135 |
# File 'lib/double_entry/account.rb', line 133 def inspect to_s end |
#scope_identity ⇒ Object
90 91 92 |
# File 'lib/double_entry/account.rb', line 90 def scope_identity scope_identifier.call(scope).to_s if scoped? end |
#to_s ⇒ Object
129 130 131 |
# File 'lib/double_entry/account.rb', line 129 def to_s "\#{Account account: #{identifier} scope: #{scope} currency: #{currency}}" end |