Class: Gares::Train
- Inherits:
-
Hashie::Dash
- Object
- Hashie::Dash
- Gares::Train
- Defined in:
- lib/gares/train.rb
Overview
Represents a train from www.sncf.com/fr/horaires-info-trafic/train
Instance Method Summary collapse
-
#arrival ⇒ Station
The arrival station of the train.
- #delayed? ⇒ Boolean
-
#departure ⇒ Station
The departure station of the train.
-
#initialize(*arguments) ⇒ Train
constructor
Initialize a new Train object with at least it’s number and departure date.
-
#number ⇒ Integer
The train number.
- #origdest ⇒ Object deprecated Deprecated.
- #platform ⇒ Object
-
#stops ⇒ Array<TrainStop>
A list of all stops between departure and arrival stations.
Constructor Details
#initialize(*arguments) ⇒ Train
Initialize a new Train object with at least it’s number and departure date
train = Gares::Train.new(num: 6704, date: Time.parse('2015-04-15'))
Gares::Train objects are lazy loaded, meaning that no HTTP request will be performed when a new object is created. An HTTP request is made Only when you use an accessor that needs remote data.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/gares/train.rb', line 27 def initialize(*arguments) attributes = arguments.first fail "Please provide a train number" unless attributes[:num].is_a?(Integer) fail "Please provide a departure date" unless attributes[:date].is_a?(Time) if attributes[:origdest] @origdest = attributes[:orig].nil? ? :orig : :dest attributes[@origdest] = Gares::Station.search(attributes[:origdest]).first attributes.delete(:origdest) end super(*arguments) end |
Instance Method Details
#arrival ⇒ Station
Returns The arrival station of the train.
62 63 64 65 66 67 68 |
# File 'lib/gares/train.rb', line 62 def arrival if dest dest else @arrival ||= TrainStop.new(document.at('tr.itinerary-end'), date) end end |
#delayed? ⇒ Boolean
76 77 78 |
# File 'lib/gares/train.rb', line 76 def delayed? retard || ([departure] + stops + [arrival]).any?(&:delayed?) end |
#departure ⇒ Station
Returns The departure station of the train.
48 49 50 51 52 53 54 |
# File 'lib/gares/train.rb', line 48 def departure if orig orig else @departure ||= TrainStop.new(document.at('tr.itinerary-start'), date) end end |
#number ⇒ Integer
Returns The train number.
43 44 45 |
# File 'lib/gares/train.rb', line 43 def number num end |
#origdest ⇒ Object
Deprecated.
71 72 73 74 |
# File 'lib/gares/train.rb', line 71 def origdest warn("[DEPRECATED] Warning: This method is deprecated, please use `orig` or `dest` instead of `origdest`") send(@origdest) end |
#platform ⇒ Object
80 81 82 |
# File 'lib/gares/train.rb', line 80 def platform voie end |