Class: DoubleEntry::Account::Instance

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/double_entry/account.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#accountObject (readonly)

Returns the value of attribute account.



69
70
71
# File 'lib/double_entry/account.rb', line 69

def 
  @account
end

#scopeObject (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.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :from (Time)
  • :to (Time)
  • :at (Time)
  • :code (Symbol)
  • :codes (Array<Symbol>)

Returns:

  • (Money)


96
97
98
# File 'lib/double_entry/account.rb', line 96

def balance(options = {})
  BalanceCalculator.calculate(self, options)
end

#call_scope_identifierObject



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

Returns:

  • (Boolean)


106
107
108
# File 'lib/double_entry/account.rb', line 106

def eql?(other)
  self == other
end

#hashObject



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

#inspectObject



126
127
128
# File 'lib/double_entry/account.rb', line 126

def inspect
  to_s
end

#scope_identityObject



79
80
81
# File 'lib/double_entry/account.rb', line 79

def scope_identity
  @scope_identity || call_scope_identifier
end

#to_sObject



122
123
124
# File 'lib/double_entry/account.rb', line 122

def to_s
  "\#{Account account: #{identifier} scope: #{scope} currency: #{currency}}"
end