Class: Gares::TrainStop

Inherits:
Object
  • Object
show all
Defined in:
lib/gares/train_stop.rb

Overview

Represents a stop for a train from www.sncf.com/fr/horaires-info-trafic/train

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nokogiri_node, date) ⇒ TrainStop

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.


33
34
35
36
37
38
# 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

Instance Attribute Details

#arrival_dateObject

Returns the value of attribute arrival_date


# File 'lib/gares/train_stop.rb', line 12

#departure_dateObject

Returns the value of attribute departure_date


# File 'lib/gares/train_stop.rb', line 6

#formatted_infoString

Returns A formatted detailed information in HTML.

Returns:

  • (String)

    A formatted detailed information in HTML.


27
28
# File 'lib/gares/train_stop.rb', line 27

attr_accessor :departure_date, :real_departure_date, :arrival_date, :real_arrival_date,
:station, :platform, :formatted_info

#platformObject

Returns the value of attribute platform


# File 'lib/gares/train_stop.rb', line 21

#real_arrival_dateObject

Returns the value of attribute real_arrival_date


# File 'lib/gares/train_stop.rb', line 15

#real_departure_dateObject

Returns the value of attribute real_departure_date


# File 'lib/gares/train_stop.rb', line 9

#stationObject

Returns the value of attribute station


# File 'lib/gares/train_stop.rb', line 18

Instance Method Details

#delayed?Boolean

Returns:

  • (Boolean)

40
41
42
# File 'lib/gares/train_stop.rb', line 40

def delayed?
  minutes_of_delay > 0
end

#minutes_of_delayInteger

Returns The amount of minutes of delay at this stop.

Returns:

  • (Integer)

    The amount of minutes of delay at this stop.


45
46
47
48
49
50
51
# 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