Class: DoubleEntry::Account::Instance
- Inherits:
-
Object
- Object
- DoubleEntry::Account::Instance
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.
37
38
39
|
# File 'lib/double_entry/account.rb', line 37
def initialize(attributes)
attributes.each { |name, value| send("#{name}=", value) }
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
41
42
43
44
45
46
47
|
# File 'lib/double_entry/account.rb', line 41
def method_missing(method, *args)
if block_given?
account.send(method, *args, &Proc.new)
else
account.send(method, *args)
end
end
|
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account.
35
36
37
|
# File 'lib/double_entry/account.rb', line 35
def account
@account
end
|
#scope ⇒ Object
Returns the value of attribute scope.
35
36
37
|
# File 'lib/double_entry/account.rb', line 35
def scope
@scope
end
|
Instance Method Details
#<=>(account) ⇒ Object
76
77
78
79
80
81
82
|
# File 'lib/double_entry/account.rb', line 76
def <=>(account)
if scoped?
[scope_identity, identifier.to_s] <=> [account.scope_identity, account.identifier.to_s]
else
identifier.to_s <=> account.identifier.to_s
end
end
|
#==(other) ⇒ Object
68
69
70
|
# File 'lib/double_entry/account.rb', line 68
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.
62
63
64
|
# File 'lib/double_entry/account.rb', line 62
def balance(options = {})
BalanceCalculator.calculate(self, options)
end
|
#eql?(other) ⇒ Boolean
72
73
74
|
# File 'lib/double_entry/account.rb', line 72
def eql?(other)
self == other
end
|
#hash ⇒ Object
84
85
86
87
88
89
90
|
# File 'lib/double_entry/account.rb', line 84
def hash
if scoped?
"#{scope_identity}:#{identifier}".hash
else
identifier.hash
end
end
|
#inspect ⇒ Object
96
97
98
|
# File 'lib/double_entry/account.rb', line 96
def inspect
to_s
end
|
#scope_identity ⇒ Object
49
50
51
|
# File 'lib/double_entry/account.rb', line 49
def scope_identity
scope_identifier.call(scope).to_s if scoped?
end
|
#to_s ⇒ Object
92
93
94
|
# File 'lib/double_entry/account.rb', line 92
def to_s
"\#{Account account: #{identifier} scope: #{scope}}"
end
|