Class: ACH::File::Reader

Inherits:
Object
  • Object
show all
Includes:
Constants
Defined in:
lib/ach/file/reader.rb

Overview

The ACH::File::Reader class builds a corresponding ACH::File object from a given set of data. The constructor takes an enum object representing a sequence of ACH lines (strings). This enum object may be a file handler, an array, or any other object that responds to the #each method.

Constant Summary

Constants included from Constants

Constants::BATCH_ADDENDA_RECORD_TYPE, Constants::BATCH_CONTROL_RECORD_TYPE, Constants::BATCH_ENTRY_RECORD_TYPE, Constants::BATCH_HEADER_RECORD_TYPE, Constants::BLOCKING_FACTOR, Constants::FILE_CONTROL_RECORD_TYPE, Constants::FILE_HEADER_RECORD_TYPE, Constants::FORMAT_CODE, Constants::RECORD_SIZE, Constants::ROWS_DELIMITER

Instance Method Summary collapse

Constructor Details

#initialize(enum) ⇒ Reader

Initialize reader.

Parameters:

  • enum (#each)


13
14
15
# File 'lib/ach/file/reader.rb', line 13

def initialize(enum)
  @enum = enum
end

Instance Method Details

#to_achACH::File

Build a ACH::File object using data obtained from @enum source.

Returns:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ach/file/reader.rb', line 20

def to_ach
  header_line, batch_lines, control_line = ach_data

  File.new do
    build_header header_line

    batch_lines.each do |batch_data|
      batch do
        build_header batch_data[:header]

        batch_data[:entries].each do |entry_line|
          build_entry entry_line

          if batch_data[:addendas].key?(entry_line)
            batch_data[:addendas][entry_line].each do |addenda_line|
              build_addenda addenda_line
            end
          end
        end

        build_control batch_data[:control]
      end
    end

    build_control control_line
  end
end