Class: WMATA::Prediction
- Defined in:
- lib/resources/prediction.rb
Overview
A resource class representing train arrival prediction information.
Available attribute methods:
-
car
- Number of cars in a particular train (usually 6 or 8). -
destination_code
- The ID of destination station. -
destination_name
- The name of destination station. -
group
- Track number (1 or 2). -
line
- ID of the metro line. -
location_code
- ID of the station where the train is arriving. -
location_name
- The name of the station where the train is arriving. -
arrival_status
- The minutes to train arrival. Can be:boarding
,:arrived
, or positive number.
Instance Attribute Summary
Attributes inherited from Resource
Class Method Summary collapse
-
.predict_for(station_code) ⇒ Object
Get train arrival prediction information for a given station; can be a station code as a string or a
Station
instance.
Instance Method Summary collapse
-
#arrival_status ⇒ Object
Get the arrival status of the train.
-
#destination ⇒ Object
Get the destination of the train for this prediction.
-
#line ⇒ Object
Get the
Line
instance for this prediction’s station’s line. -
#line_code ⇒ Object
Get the line code the line this prediction’s station is on.
-
#location ⇒ Object
(also: #station)
Get the arriving station this prediction applies to.
Methods inherited from Resource
endpoint, get_all, #initialize, #method_missing, service, to_query_string
Constructor Details
This class inherits a constructor from WMATA::Resource
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class WMATA::Resource
Class Method Details
.predict_for(station_code) ⇒ Object
Get train arrival prediction information for a given station; can be a station code as a string or a Station
instance.
20 21 22 23 |
# File 'lib/resources/prediction.rb', line 20 def self.predict_for(station_code) url = WMATA.base_url % [service, "GetPrediction/#{station_code.to_s}", ""] HTTParty.get(url).first.last.map {|values| new(values) } end |
Instance Method Details
#arrival_status ⇒ Object
Get the arrival status of the train. Can be :boarding
, :arrived
, or the number of minutes until the train will arrive.
49 50 51 52 53 54 55 56 57 |
# File 'lib/resources/prediction.rb', line 49 def arrival_status if @attrs['Min'] == "BRD" :boarding elsif @attrs['Min'] == "ARR" :arrived else @attrs['Min'].to_i end end |
#destination ⇒ Object
Get the destination of the train for this prediction.
33 34 35 |
# File 'lib/resources/prediction.rb', line 33 def destination @destination ||= Station.get(@attrs['DestinationCode']) end |
#line ⇒ Object
Get the Line
instance for this prediction’s station’s line.
43 44 45 |
# File 'lib/resources/prediction.rb', line 43 def line @line ||= Line.get(@attrs['Line']) end |
#line_code ⇒ Object
Get the line code the line this prediction’s station is on.
38 39 40 |
# File 'lib/resources/prediction.rb', line 38 def line_code @attrs['Line'] end |