Class: MudratProjector::Projection

Inherits:
Object
  • Object
show all
Defined in:
lib/mudrat_projector/projection.rb

Defined Under Namespace

Classes: SequenceEntry

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(range: date_range, chart: chart_of_accounts) ⇒ Projection

Returns a new instance of Projection.



15
16
17
18
19
20
# File 'lib/mudrat_projector/projection.rb', line 15

def initialize range: date_range, chart: chart_of_accounts
  @chart                = chart
  @batch_id             = 0
  @range                = range
  @transaction_sequence = []
end

Instance Attribute Details

#rangeObject (readonly)

Returns the value of attribute range.



3
4
5
# File 'lib/mudrat_projector/projection.rb', line 3

def range
  @range
end

Instance Method Details

#<<(transaction) ⇒ Object



22
23
24
# File 'lib/mudrat_projector/projection.rb', line 22

def << transaction
  @transaction_sequence.push SequenceEntry.new(transaction, @batch_id)
end

#add_transaction_batch(batch) ⇒ Object



26
27
28
29
30
31
# File 'lib/mudrat_projector/projection.rb', line 26

def add_transaction_batch batch
  batch.each do |transaction| 
    self << transaction
    @batch_id += 1
  end
end

#project!Object



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

def project!
  freeze
  transaction_sequence.each do |transaction|
    @chart.apply_transaction transaction
    yield transaction if block_given?
  end
end

#transaction_sequenceObject



41
42
43
# File 'lib/mudrat_projector/projection.rb', line 41

def transaction_sequence
  @transaction_sequence.tap(&:sort!).map &:transaction
end