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.



75
76
77
78
79
# File 'lib/double_entry/account.rb', line 75

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.



72
73
74
# File 'lib/double_entry/account.rb', line 72

def 
  @account
end

#scopeObject (readonly)

Returns the value of attribute scope.



72
73
74
# File 'lib/double_entry/account.rb', line 72

def scope
  @scope
end

Instance Method Details

#<=>(account) ⇒ Object



108
109
110
# File 'lib/double_entry/account.rb', line 108

def <=>()
  [scope_identity.to_s, identifier.to_s] <=> [.scope_identity.to_s, .identifier.to_s]
end

#==(other) ⇒ Object



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

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)


94
95
96
# File 'lib/double_entry/account.rb', line 94

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

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

def eql?(other)
  self == other
end

#hashObject



112
113
114
115
116
117
118
# File 'lib/double_entry/account.rb', line 112

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

#inspectObject



124
125
126
# File 'lib/double_entry/account.rb', line 124

def inspect
  to_s
end

#scope_identityObject



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

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

#to_sObject



120
121
122
# File 'lib/double_entry/account.rb', line 120

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