Class: NationalRail::VirginLiveDepartureBoards::DetailsPageParser
- Inherits:
-
Object
- Object
- NationalRail::VirginLiveDepartureBoards::DetailsPageParser
- Includes:
- CellParser
- Defined in:
- lib/national-rail/virgin_live_departure_boards/details_page_parser.rb
Instance Method Summary collapse
-
#initialize(doc) ⇒ DetailsPageParser
constructor
A new instance of DetailsPageParser.
- #parse ⇒ Object
Methods included from CellParser
Constructor Details
#initialize(doc) ⇒ DetailsPageParser
Returns a new instance of DetailsPageParser.
7 8 9 10 |
# File 'lib/national-rail/virgin_live_departure_boards/details_page_parser.rb', line 7 def initialize(doc) @doc = doc @time_parser = TimeParser.new end |
Instance Method Details
#parse ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/national-rail/virgin_live_departure_boards/details_page_parser.rb', line 12 def parse will_call_at = [] table = @doc/"table[@summary='Will call at']" if table.any? (table/"tbody tr").each do |tr| tds = tr/"td" next unless tds.length == 3 will_call_at.push({ :station => cell_text(tds[0]), :timetabled_arrival => @time_parser.parse(cell_text(tds[1])), :expected_arrival => @time_parser.parse(cell_text(tds[2])) }) end end previous_calling_points = [] table = @doc/"table[@summary='Previous calling points']" if table.any? (table/"tbody tr").each do |tr| tds = tr/"td" next unless tds.length == 4 previous_calling_points.push({ :station => cell_text(tds[0]), :timetabled_departure => @time_parser.parse(cell_text(tds[1])), :expected_departure => @time_parser.parse(cell_text(tds[2])), :actual_departure => @time_parser.parse(cell_text(tds[3])) }) end end { :will_call_at => will_call_at, :previous_calling_points => previous_calling_points } end |