Class: Ach::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/ach/parser.rb

Class Method Summary collapse

Class Method Details

.parse_file(observer) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ach/parser.rb', line 3

def self.parse_file(observer)
  raise Exception.new "No file supplied. Cannot proceed!" if observer.filename.nil?
  File.open(observer.filename).each do |l|
    case l[0].chr
    when "1"
      file_header = FileHeaderRecord.decode(l)
      observer.file_header(file_header)
    when "5"
      batch_header = BatchHeaderRecord.decode(l)
      observer.batch_header(batch_header)
    when "6"
      entry_detail = EntryDetailRecord.decode(l)
      observer.entry_detail(entry_detail)
    when "8"
      batch_control = BatchControlRecord.decode(l)
      observer.batch_control(batch_control)
    when "9"
      unless (l.count "9") == 94
        file_control = FileControlRecord.decode(l)
        observer.file_control(file_control)
      end
    else
    end
  end
end