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.
17
18
19
|
# File 'lib/double_entry/account.rb', line 17
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
21
22
23
24
25
26
27
|
# File 'lib/double_entry/account.rb', line 21
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.
15
16
17
|
# File 'lib/double_entry/account.rb', line 15
def account
@account
end
|
#scope ⇒ Object
Returns the value of attribute scope.
15
16
17
|
# File 'lib/double_entry/account.rb', line 15
def scope
@scope
end
|
Instance Method Details
#<=>(account) ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/double_entry/account.rb', line 47
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
39
40
41
|
# File 'lib/double_entry/account.rb', line 39
def ==(other)
other.is_a?(self.class) && identifier == other.identifier && scope_identity == other.scope_identity
end
|
#balance(args = {}) ⇒ Object
33
34
35
|
# File 'lib/double_entry/account.rb', line 33
def balance(args = {})
DoubleEntry.balance(self, args)
end
|
#eql?(other) ⇒ Boolean
43
44
45
|
# File 'lib/double_entry/account.rb', line 43
def eql?(other)
self == other
end
|
#hash ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/double_entry/account.rb', line 55
def hash
if scoped?
"#{scope_identity}:#{identifier}".hash
else
identifier.hash
end
end
|
#inspect ⇒ Object
67
68
69
|
# File 'lib/double_entry/account.rb', line 67
def inspect
to_s
end
|
#scope_identity ⇒ Object
29
30
31
|
# File 'lib/double_entry/account.rb', line 29
def scope_identity
scope_identifier.call(scope).to_s if scoped?
end
|
#to_s ⇒ Object
63
64
65
|
# File 'lib/double_entry/account.rb', line 63
def to_s
"\#{Account account: #{identifier} scope: #{scope}}"
end
|