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(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

#accountObject

Returns the value of attribute account.



49
50
51
# File 'lib/double_entry/account.rb', line 49

def 
  @account
end

#scopeObject

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
86
87
88
89
# File 'lib/double_entry/account.rb', line 83

def <=>()
  if scoped?
    [scope_identity, identifier.to_s] <=> [.scope_identity, .identifier.to_s]
  else
    identifier.to_s <=> .identifier.to_s
  end
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.

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)


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

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

def eql?(other)
  self == other
end

#hashObject



91
92
93
94
95
96
97
# File 'lib/double_entry/account.rb', line 91

def hash
  if scoped?
    "#{scope_identity}:#{identifier}".hash
  else
    identifier.hash
  end
end

#inspectObject



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

def inspect
  to_s
end

#scope_identityObject



56
57
58
# File 'lib/double_entry/account.rb', line 56

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

#to_sObject



99
100
101
# File 'lib/double_entry/account.rb', line 99

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