Class: RailFeeds::NetworkRail::Schedule::Parser::CIF

Inherits:
RailFeeds::NetworkRail::Schedule::Parser show all
Defined in:
lib/rail_feeds/network_rail/schedule/parser/cif.rb

Overview

A class for parsing schedule data read from CIF schedule file(s).

Constant Summary collapse

UNDERSTOOD_ROWS =
%w[
  HD TI TA TD AAN AAD AAR BSN BSD BSR BX LO LI LT CR ZZ
].freeze

Instance Method Summary collapse

Methods inherited from RailFeeds::NetworkRail::Schedule::Parser

#initialize, #parse_file, #stop_parsing

Methods included from Logging

formatter, included, #logger, logger, #logger=, logger=

Constructor Details

This class inherits a constructor from RailFeeds::NetworkRail::Schedule::Parser

Instance Method Details

#parse_line(line) ⇒ Object

Parse the data on a single CIF line

Parameters:

  • line (String)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rail_feeds/network_rail/schedule/parser/cif.rb', line 15

def parse_line(line)
  catch :line_parsed do
    UNDERSTOOD_ROWS.each do |record_type|
      if line.start_with?(record_type)
        send "parse_#{record_type.downcase}_line", line.chomp
        throw :line_parsed
      end
    end

    if line[0].eql?('/')
      parse_comment_line line.chomp
      throw :line_parsed
    end

    logger.error "Can't understand line: #{line.chomp.inspect}"
  end
end