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
Returns the value of attribute account.
-
#scope ⇒ Object
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(attributes) ⇒ Instance
constructor
A new instance of Instance.
- #inspect ⇒ Object
- #scope_identity ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Instance
Returns a new instance of Instance.
52 53 54 |
# File 'lib/double_entry/account.rb', line 52 def initialize(attributes) attributes.each { |name, value| send("#{name}=", value) } end |
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account.
49 50 51 |
# File 'lib/double_entry/account.rb', line 49 def account @account end |
#scope ⇒ Object
Returns the value of attribute scope.
49 50 51 |
# File 'lib/double_entry/account.rb', line 49 def scope @scope end |
Instance Method Details
#<=>(account) ⇒ Object
83 84 85 |
# File 'lib/double_entry/account.rb', line 83 def <=>(account) [scope_identity.to_s, identifier.to_s] <=> [account.scope_identity.to_s, account.identifier.to_s] end |
#==(other) ⇒ Object
75 76 77 |
# File 'lib/double_entry/account.rb', line 75 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.
69 70 71 |
# File 'lib/double_entry/account.rb', line 69 def balance( = {}) BalanceCalculator.calculate(self, ) end |
#eql?(other) ⇒ Boolean
79 80 81 |
# File 'lib/double_entry/account.rb', line 79 def eql?(other) self == other end |
#hash ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/double_entry/account.rb', line 87 def hash if scoped? "#{scope_identity}:#{identifier}".hash else identifier.hash end end |
#inspect ⇒ Object
99 100 101 |
# File 'lib/double_entry/account.rb', line 99 def inspect to_s end |
#scope_identity ⇒ Object
56 57 58 |
# File 'lib/double_entry/account.rb', line 56 def scope_identity scope_identifier.call(scope).to_s if scoped? end |
#to_s ⇒ Object
95 96 97 |
# File 'lib/double_entry/account.rb', line 95 def to_s "\#{Account account: #{identifier} scope: #{scope}}" end |