Class: MudratProjector::Transaction

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/mudrat_projector/transaction.rb

Direct Known Subclasses

ScheduledTransaction

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Transaction

Returns a new instance of Transaction.



7
8
9
10
11
# File 'lib/mudrat_projector/transaction.rb', line 7

def initialize params = {}
  @date        = params.fetch :date
  self.credits = extract_entry_params :credit, params
  self.debits  = extract_entry_params :debit,  params
end

Instance Attribute Details

#creditsObject

Returns the value of attribute credits.



5
6
7
# File 'lib/mudrat_projector/transaction.rb', line 5

def credits
  @credits
end

#dateObject (readonly)

Returns the value of attribute date.



5
6
7
# File 'lib/mudrat_projector/transaction.rb', line 5

def date
  @date
end

#debitsObject

Returns the value of attribute debits.



5
6
7
# File 'lib/mudrat_projector/transaction.rb', line 5

def debits
  @debits
end

Instance Method Details

#balanced?Boolean

Returns:

  • (Boolean)


13
14
15
16
17
# File 'lib/mudrat_projector/transaction.rb', line 13

def balanced?
  sum_credits = build_set_for_balance credits
  sum_debits  = build_set_for_balance debits
  (sum_credits ^ sum_debits).empty?
end

#each(&block) ⇒ Object



27
28
29
30
# File 'lib/mudrat_projector/transaction.rb', line 27

def each &block
  credits.each &block
  debits.each &block
end

#slice(slice_date) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/mudrat_projector/transaction.rb', line 32

def slice slice_date
  if date > slice_date
    [[], self]
  else
    [[self], nil]
  end
end