Class: RailFeeds::NetworkRail::Schedule::Parser
- Inherits:
-
Object
- Object
- RailFeeds::NetworkRail::Schedule::Parser
- Includes:
- Logging
- Defined in:
- lib/rail_feeds/network_rail/schedule/parser.rb,
lib/rail_feeds/network_rail/schedule/parser/cif.rb,
lib/rail_feeds/network_rail/schedule/parser/json.rb
Overview
A parent class for parsing schedule data read from schedule file(s). Children need to implement a parse_line method.
Defined Under Namespace
Instance Method Summary collapse
-
#initialize(logger: nil, on_header: nil, on_trailer: nil, on_comment: nil, on_tiploc_create: nil, on_tiploc_update: nil, on_tiploc_delete: nil, on_association_create: nil, on_association_update: nil, on_association_delete: nil, on_train_schedule_create: nil, on_train_schedule_update: nil, on_train_schedule_delete: nil) ⇒ Parser
constructor
rubocop:disable Metrics/ParameterLists Initialize a new data.
-
#parse_file(file) ⇒ Object
Parse the data in file.
- #parse_line(_line) ⇒ Object
-
#stop_parsing ⇒ Object
Stop parsing the current file.
Methods included from Logging
formatter, included, #logger, logger, #logger=, logger=
Constructor Details
#initialize(logger: nil, on_header: nil, on_trailer: nil, on_comment: nil, on_tiploc_create: nil, on_tiploc_update: nil, on_tiploc_delete: nil, on_association_create: nil, on_association_update: nil, on_association_delete: nil, on_train_schedule_create: nil, on_train_schedule_update: nil, on_train_schedule_delete: nil) ⇒ Parser
rubocop:disable Metrics/ParameterLists Initialize a new data.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rail_feeds/network_rail/schedule/parser.rb', line 51 def initialize( logger: nil, on_header: nil, on_trailer: nil, on_comment: nil, on_tiploc_create: nil, on_tiploc_update: nil, on_tiploc_delete: nil, on_association_create: nil, on_association_update: nil, on_association_delete: nil, on_train_schedule_create: nil, on_train_schedule_update: nil, on_train_schedule_delete: nil ) self.logger = logger unless logger.nil? @on_header = on_header @on_trailer = on_trailer @on_tiploc_create = on_tiploc_create @on_tiploc_update = on_tiploc_update @on_tiploc_delete = on_tiploc_delete @on_association_create = on_association_create @on_association_update = on_association_update @on_association_delete = on_association_delete @on_train_schedule_create = on_train_schedule_create @on_train_schedule_update = on_train_schedule_update @on_train_schedule_delete = on_train_schedule_delete @on_comment = on_comment end |
Instance Method Details
#parse_file(file) ⇒ Object
Parse the data in file.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/rail_feeds/network_rail/schedule/parser.rb', line 78 def parse_file(file) @file_ended = false @stop_parsing = false file.each_line do |line| parse_line line if @stop_parsing logger.debug "Parsing of file #{file} was stopped." break end end fail "File is incomplete. #{file}" unless @stop_parsing || @file_ended end |
#parse_line(_line) ⇒ Object
94 95 96 |
# File 'lib/rail_feeds/network_rail/schedule/parser.rb', line 94 def parse_line(_line) fail 'parse_file MUST be implemented in the child class.' end |
#stop_parsing ⇒ Object
Stop parsing the current file.
99 100 101 |
# File 'lib/rail_feeds/network_rail/schedule/parser.rb', line 99 def stop_parsing @stop_parsing = true end |