Class: BAI2::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/bai2_ruby/writer.rb

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ Writer

Returns a new instance of Writer.



5
6
7
# File 'lib/bai2_ruby/writer.rb', line 5

def initialize(file)
  @file = file
end

Instance Method Details

#generateObject

rubocop:disable Metrics/AbcSize



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bai2_ruby/writer.rb', line 10

def generate
  content = []
  content << generate_file_header(@file.header)

  @file.groups.each do |group|
    content << generate_group_header(group.header)

    group.accounts.each do ||
      content << (.header)

      .transactions.each do |transaction|
        content << generate_transaction(transaction)
      end

      content << (.trailer)
    end

    content << generate_group_trailer(group.trailer)
  end

  content << generate_file_trailer(@file.trailer)
  content.join("\n")
end