class RailFeeds::NetworkRail::Schedule::Parser::CIF
A class for parsing schedule data read from CIF
schedule file(s).
Constants
- UNDERSTOOD_ROWS
Public Instance Methods
parse_line(line)
click to toggle source
Parse the data on a single CIF
line @param [String] line
# 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
Private Instance Methods
finish_current_train()
click to toggle source
# File lib/rail_feeds/network_rail/schedule/parser/cif.rb, line 113 def finish_current_train return if @current_train.nil? case @current_train_action when :create @on_train_schedule_create&.call self, @current_train when :update @on_train_schedule_update&.call self, @current_train end @current_train = nil end
parse_aad_line(line)
click to toggle source
Association
Delete record
# File lib/rail_feeds/network_rail/schedule/parser/cif.rb, line 71 def parse_aad_line(line) @on_association_delete&.call self, Association.from_cif(line) end
parse_aan_line(line)
click to toggle source
Association
New record
# File lib/rail_feeds/network_rail/schedule/parser/cif.rb, line 61 def parse_aan_line(line) @on_association_create&.call self, Association.from_cif(line) end
parse_aar_line(line)
click to toggle source
Association
Revise record
# File lib/rail_feeds/network_rail/schedule/parser/cif.rb, line 66 def parse_aar_line(line) @on_association_update&.call self, Association.from_cif(line) end
parse_bsd_line(line)
click to toggle source
Train schedule record - basic schedule - delete
# File lib/rail_feeds/network_rail/schedule/parser/cif.rb, line 84 def parse_bsd_line(line) finish_current_train train = TrainSchedule.new train.update_from_cif line @on_train_schedule_delete&.call self, train end
parse_bsn_line(line)
click to toggle source
Train schedule record - basic schedule - new
# File lib/rail_feeds/network_rail/schedule/parser/cif.rb, line 76 def parse_bsn_line(line) finish_current_train @current_train = TrainSchedule.new @current_train.update_from_cif line @current_train_action = :create end
parse_bsr_line(line)
click to toggle source
Train schedule record - basic schedule - revise
# File lib/rail_feeds/network_rail/schedule/parser/cif.rb, line 92 def parse_bsr_line(line) finish_current_train @current_train = TrainSchedule.new @current_train.update_from_cif line @current_train_action = :update end
parse_bx_line(line)
click to toggle source
Train schedule record - basic schedule extra details
# File lib/rail_feeds/network_rail/schedule/parser/cif.rb, line 100 def parse_bx_line(line) @current_train.update_from_cif line end
parse_comment_line(line)
click to toggle source
Comment
# File lib/rail_feeds/network_rail/schedule/parser/cif.rb, line 134 def parse_comment_line(line) @on_comment&.call self, line[1..-1] end
parse_hd_line(line)
click to toggle source
Header
record
# File lib/rail_feeds/network_rail/schedule/parser/cif.rb, line 36 def parse_hd_line(line) header = Header.from_cif(line) logger.info "Starting Parse. #{header}" @on_header&.call self, header end
parse_ta_line(line)
click to toggle source
TIPLOC Amend record
# File lib/rail_feeds/network_rail/schedule/parser/cif.rb, line 48 def parse_ta_line(line) tiploc = Tiploc.from_cif(line) old_id = tiploc.tiploc tiploc.tiploc = line[2..8].strip @on_tiploc_update&.call self, old_id, tiploc end
parse_td_line(line)
click to toggle source
TIPLOC Delete record
# File lib/rail_feeds/network_rail/schedule/parser/cif.rb, line 56 def parse_td_line(line) @on_tiploc_delete&.call self, Tiploc.from_cif(line).tiploc end
parse_ti_line(line)
click to toggle source
TIPLOC Insert record
# File lib/rail_feeds/network_rail/schedule/parser/cif.rb, line 43 def parse_ti_line(line) @on_tiploc_create&.call self, Tiploc.from_cif(line) end
parse_zz_line(_line)
click to toggle source
Trailer record
# File lib/rail_feeds/network_rail/schedule/parser/cif.rb, line 127 def parse_zz_line(_line) finish_current_train @file_ended = true @on_trailer&.call self end