class Gares::TrainStop
Represents a stop for a train from www.sncf.com/fr/horaires-info-trafic/train
Attributes
arrival_date[RW]
@!attribute formatted_info
@return [String] A formatted detailed information in HTML.
departure_date[RW]
@!attribute formatted_info
@return [String] A formatted detailed information in HTML.
formatted_info[RW]
@!attribute formatted_info
@return [String] A formatted detailed information in HTML.
platform[RW]
@!attribute formatted_info
@return [String] A formatted detailed information in HTML.
real_arrival_date[RW]
@!attribute formatted_info
@return [String] A formatted detailed information in HTML.
real_departure_date[RW]
@!attribute formatted_info
@return [String] A formatted detailed information in HTML.
station[RW]
@!attribute formatted_info
@return [String] A formatted detailed information in HTML.
Public Class Methods
new(nokogiri_node, date)
click to toggle source
Given the HTML node from sncf.com/fr/horaires-info-trafic/train containing the stop and the date
for this train stop. The object gathers all useful information about the stop made by the train.
# File lib/gares/train_stop.rb, line 33 def initialize(nokogiri_node, date) initialize_dates(nokogiri_node, date) initialize_station(nokogiri_node) @platform = nokogiri_node.at('td.track').inner_html.strip @formatted_info = nokogiri_node.at('td.info').inner_html.strip end
Public Instance Methods
delayed?()
click to toggle source
# File lib/gares/train_stop.rb, line 40 def delayed? minutes_of_delay > 0 end
minutes_of_delay()
click to toggle source
@return [Integer] The amount of minutes of delay at this stop.
# File lib/gares/train_stop.rb, line 45 def minutes_of_delay if @real_departure_date (@real_departure_date - @departure_date) / 60 else 0 end end
Private Instance Methods
initialize_dates(node, date)
click to toggle source
# File lib/gares/train_stop.rb, line 55 def initialize_dates(node, date) raw_time = node.at('td.time').inner_html.strip raw_real_time = node.at('td.new-schedule').inner_html.strip raw_arrival_time = raw_time.split('<br/>').first raw_departure_time = raw_time.split('<br/>').last raw_real_arrival_time = raw_real_time.split('<br/>').first raw_real_departure_time = raw_real_time.split('<br/>').last @departure_date = Time.parse(raw_departure_time, date) @arrival_date = Time.parse(raw_arrival_time, date) if raw_real_departure_time @real_departure_date = Time.parse(raw_real_departure_time, date) end if raw_real_arrival_time @real_arrival_date = Time.parse(raw_real_arrival_time, date) end end
initialize_station(node)
click to toggle source
# File lib/gares/train_stop.rb, line 73 def initialize_station(node) raw_name = node.at('td.stations div.station').inner_html.strip stations = Station.search(raw_name) @station = if stations.size > 1 raw_name.gsub!(/[ -]/, '.*') exact_match = /^#{raw_name}$/i begin_match = /^#{raw_name}/i end_match = /#{raw_name}$/ middle_match = /#{raw_name}/i stations.find do |station| station.name.to_ascii.match(exact_match) end || stations.find do |station| station.name.to_ascii.match(begin_match) end || stations.find do |station| station.name.to_ascii.match(end_match) end || stations.find do |station| station.name.to_ascii.match(middle_match) end else stations.first end end