Class: DtaParser::File

Inherits:
Object
  • Object
show all
Defined in:
lib/dta_parser/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename) ⇒ File

Returns a new instance of File.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dta_parser/file.rb', line 7

def initialize(filename)
  self.raw = ::File.open(filename, "r") { |f| f.read }
  self.booking_records ||= []

  records.each do |record|
    record_type = record[4, 1]
    case record_type
    when "A"
      self.header_record = DtaParser::HeaderRecord.new(record)
    when "C"
      self.booking_records << DtaParser::BookingRecord.new(record)
    when "E"
      self.footer_record = DtaParser::FooterRecord.new(record)
    else
      raise "Unknown record type: #{record_type}"
    end
  end
end

Instance Attribute Details

#booking_recordsObject

Returns the value of attribute booking_records.



5
6
7
# File 'lib/dta_parser/file.rb', line 5

def booking_records
  @booking_records
end

Returns the value of attribute footer_record.



5
6
7
# File 'lib/dta_parser/file.rb', line 5

def footer_record
  @footer_record
end

#header_recordObject

Returns the value of attribute header_record.



5
6
7
# File 'lib/dta_parser/file.rb', line 5

def header_record
  @header_record
end

#rawObject

Returns the value of attribute raw.



5
6
7
# File 'lib/dta_parser/file.rb', line 5

def raw
  @raw
end