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.



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?
    .send(method, *args, &Proc.new)
  else
    .send(method, *args)
  end
end

Instance Attribute Details

#accountObject

Returns the value of attribute account.



15
16
17
# File 'lib/double_entry/account.rb', line 15

def 
  @account
end

#scopeObject

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

Returns:

  • (Boolean)


43
44
45
# File 'lib/double_entry/account.rb', line 43

def eql?(other)
  self == other
end

#hashObject



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

#inspectObject



67
68
69
# File 'lib/double_entry/account.rb', line 67

def inspect
  to_s
end

#scope_identityObject



29
30
31
# File 'lib/double_entry/account.rb', line 29

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

#to_sObject



63
64
65
# File 'lib/double_entry/account.rb', line 63

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