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.
- #call_scope_identifier ⇒ Object
- #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.
72 73 74 75 76 77 |
# File 'lib/double_entry/account.rb', line 72 def initialize(args) @account = args[:account] @scope = args[:scope] @scope_identity = args[:scope_identity] ensure_scope_is_valid end |
Instance Attribute Details
#account ⇒ Object (readonly)
Returns the value of attribute account.
69 70 71 |
# File 'lib/double_entry/account.rb', line 69 def account @account end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
69 70 71 |
# File 'lib/double_entry/account.rb', line 69 def scope @scope end |
Instance Method Details
#<=>(other) ⇒ Object
110 111 112 |
# File 'lib/double_entry/account.rb', line 110 def <=>(other) [scope_identity.to_s, identifier.to_s] <=> [other.scope_identity.to_s, other.identifier.to_s] end |
#==(other) ⇒ Object
102 103 104 |
# File 'lib/double_entry/account.rb', line 102 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.
96 97 98 |
# File 'lib/double_entry/account.rb', line 96 def balance( = {}) BalanceCalculator.calculate(self, ) end |
#call_scope_identifier ⇒ Object
83 84 85 |
# File 'lib/double_entry/account.rb', line 83 def call_scope_identifier scope_identifier.call(scope).to_s if scoped? end |
#eql?(other) ⇒ Boolean
106 107 108 |
# File 'lib/double_entry/account.rb', line 106 def eql?(other) self == other end |
#hash ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/double_entry/account.rb', line 114 def hash if scoped? "#{scope_identity}:#{identifier}".hash else identifier.hash end end |
#inspect ⇒ Object
126 127 128 |
# File 'lib/double_entry/account.rb', line 126 def inspect to_s end |
#scope_identity ⇒ Object
79 80 81 |
# File 'lib/double_entry/account.rb', line 79 def scope_identity @scope_identity || call_scope_identifier end |
#to_s ⇒ Object
122 123 124 |
# File 'lib/double_entry/account.rb', line 122 def to_s "\#{Account account: #{identifier} scope: #{scope} currency: #{currency}}" end |