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
- #<=>(account) ⇒ 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.
75 76 77 78 79 |
# File 'lib/double_entry/account.rb', line 75 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.
72 73 74 |
# File 'lib/double_entry/account.rb', line 72 def account @account end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
72 73 74 |
# File 'lib/double_entry/account.rb', line 72 def scope @scope end |
Instance Method Details
#<=>(account) ⇒ Object
108 109 110 |
# File 'lib/double_entry/account.rb', line 108 def <=>(account) [scope_identity.to_s, identifier.to_s] <=> [account.scope_identity.to_s, account.identifier.to_s] end |
#==(other) ⇒ Object
100 101 102 |
# File 'lib/double_entry/account.rb', line 100 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.
94 95 96 |
# File 'lib/double_entry/account.rb', line 94 def balance( = {}) BalanceCalculator.calculate(self, ) end |
#eql?(other) ⇒ Boolean
104 105 106 |
# File 'lib/double_entry/account.rb', line 104 def eql?(other) self == other end |
#hash ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/double_entry/account.rb', line 112 def hash if scoped? "#{scope_identity}:#{identifier}".hash else identifier.hash end end |
#inspect ⇒ Object
124 125 126 |
# File 'lib/double_entry/account.rb', line 124 def inspect to_s end |
#scope_identity ⇒ Object
81 82 83 |
# File 'lib/double_entry/account.rb', line 81 def scope_identity scope_identifier.call(scope).to_s if scoped? end |
#to_s ⇒ Object
120 121 122 |
# File 'lib/double_entry/account.rb', line 120 def to_s "\#{Account account: #{identifier} scope: #{scope} currency: #{currency}}" end |