Class: Headache::DocumentParser

Inherits:
Object
  • Object
show all
Defined in:
lib/headache/document_parser.rb

Constant Summary collapse

LINE_SEPARATOR =
"\r\n".freeze

Instance Method Summary collapse

Constructor Details

#initialize(string_or_file) ⇒ DocumentParser

Returns a new instance of DocumentParser.



5
6
7
# File 'lib/headache/document_parser.rb', line 5

def initialize(string_or_file)
  @ach_string = string_or_file.respond_to?(:read) ? string_or_file.read : string_or_file
end

Instance Method Details

#parseObject



9
10
11
12
13
14
15
16
17
# File 'lib/headache/document_parser.rb', line 9

def parse
  fail Headache::InvalidRecordType, invalid_fail_message if invalid_ach?

  Headache::Document.new(
    Record::FileHeader.new(nil).parse(records.shift),
    Record::FileControl.new(nil).parse(records.pop),
    get_batches.map { |b| Headache::Batch.new(self).parse(b) }
  )
end