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.



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

#accountObject (readonly)

Returns the value of attribute account.



81
82
83
# File 'lib/double_entry/account.rb', line 81

def 
  @account
end

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

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)


103
104
105
# File 'lib/double_entry/account.rb', line 103

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/double_entry/account.rb', line 113

def eql?(other)
  self == other
end

#hashObject



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

#inspectObject



133
134
135
# File 'lib/double_entry/account.rb', line 133

def inspect
  to_s
end

#scope_identityObject



90
91
92
# File 'lib/double_entry/account.rb', line 90

def scope_identity
  scope_identifier.call(scope).to_s if scoped?
end

#to_sObject



129
130
131
# File 'lib/double_entry/account.rb', line 129

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