Class: CTA::Train::Prediction
- Inherits:
-
Object
- Object
- CTA::Train::Prediction
- Defined in:
- lib/cta_redux/models/train.rb
Instance Attribute Summary collapse
-
#approaching ⇒ true, false
readonly
True if this train is considered to be ‘approaching’ the next_station by the CTA.
-
#arrival_time ⇒ DateTime
readonly
The time this train is predicted to arrive at the next_station.
-
#delayed ⇒ true, false
readonly
True if this train is considered to be ‘delayed’ by the CTA.
-
#destination ⇒ CTA::Stop
readonly
The final Stop of this train.
-
#direction ⇒ String
readonly
A human-readable direction of this train, eg “O’Hare-bound”.
-
#flags ⇒ String
readonly
Flags for this train.
-
#minutes ⇒ Integer
readonly
The number of minutes until this train arrives at the next_station.
-
#next_station ⇒ CTA::Stop
readonly
The next Stop of this train.
-
#prediction_generated_at ⇒ DateTime
readonly
The time this Prediction was generated on the TrainTracker servers.
-
#route ⇒ CTA::Route
readonly
The Route this train is running.
-
#run ⇒ String
readonly
The run identifier for this train.
-
#scheduled ⇒ true, false
readonly
True if this train has not yet left it’s origin station and started it’s run.
-
#seconds ⇒ Integer
readonly
The number of seconds until this train arrives at the next_station.
-
#trip ⇒ CTA::Trip
readonly
The CTA::Trip associated with this train.
Instance Method Summary collapse
-
#initialize(data) ⇒ Prediction
constructor
A new instance of Prediction.
Constructor Details
#initialize(data) ⇒ Prediction
Returns a new instance of Prediction.
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/cta_redux/models/train.rb', line 120 def initialize(data) @run = data["rn"] @trip = CTA::Trip.where(:schd_trip_id => "R#{@run}").first @destination = CTA::Stop.where(:stop_id => data["destSt"]).first @next_station = CTA::Stop.where(:stop_id => (data["staId"] || data["nextStaId"])).first @prediction_generated_at = DateTime.parse(data["prdt"]) @arrival_time = DateTime.parse(data["arrT"]) @seconds = @arrival_time.to_time - @prediction_generated_at.to_time @minutes = (@seconds / 60).ceil @approaching = (data["isApp"] == "1") @delayed = (data["isDly"] == "1") @scheduled = (data["isSch"] == "1") @flags = data["flags"] @route = @trip.route @direction = L_ROUTES[@route.route_id.downcase][:directions][data["trDr"]] end |
Instance Attribute Details
#approaching ⇒ true, false (readonly)
Returns True if this train is considered to be ‘approaching’ the next_station by the CTA.
106 107 108 |
# File 'lib/cta_redux/models/train.rb', line 106 def approaching @approaching end |
#arrival_time ⇒ DateTime (readonly)
Returns The time this train is predicted to arrive at the next_station.
100 101 102 |
# File 'lib/cta_redux/models/train.rb', line 100 def arrival_time @arrival_time end |
#delayed ⇒ true, false (readonly)
The CTA considers a train ‘delayed’ if it’s not progressing along the tracks. This is not an indication that a predicted arrival time will be later than a scheduled arrival time (which is how most people would consider a train to be ‘delayed’). The CTA recommends that you indicate a train is ‘delayed’ rather than continuing to display the last predicted arrival time, which may no longer be accurate.
Returns True if this train is considered to be ‘delayed’ by the CTA.
114 115 116 |
# File 'lib/cta_redux/models/train.rb', line 114 def delayed @delayed end |
#destination ⇒ CTA::Stop (readonly)
Returns The final Stop of this train.
92 93 94 |
# File 'lib/cta_redux/models/train.rb', line 92 def destination @destination end |
#direction ⇒ String (readonly)
Returns A human-readable direction of this train, eg “O’Hare-bound”.
94 95 96 |
# File 'lib/cta_redux/models/train.rb', line 94 def direction @direction end |
#flags ⇒ String (readonly)
Returns Flags for this train. Unused at this time.
116 117 118 |
# File 'lib/cta_redux/models/train.rb', line 116 def flags @flags end |
#minutes ⇒ Integer (readonly)
Returns The number of minutes until this train arrives at the next_station.
102 103 104 |
# File 'lib/cta_redux/models/train.rb', line 102 def minutes @minutes end |
#next_station ⇒ CTA::Stop (readonly)
Returns The next Stop of this train.
96 97 98 |
# File 'lib/cta_redux/models/train.rb', line 96 def next_station @next_station end |
#prediction_generated_at ⇒ DateTime (readonly)
Returns The time this CTA::Train::Prediction was generated on the TrainTracker servers.
98 99 100 |
# File 'lib/cta_redux/models/train.rb', line 98 def prediction_generated_at @prediction_generated_at end |
#route ⇒ CTA::Route (readonly)
Returns The Route this train is running.
118 119 120 |
# File 'lib/cta_redux/models/train.rb', line 118 def route @route end |
#run ⇒ String (readonly)
This is returned as a string, because the API will return results like “004” and the leading zeroes are important.
Returns The run identifier for this train.
88 89 90 |
# File 'lib/cta_redux/models/train.rb', line 88 def run @run end |
#scheduled ⇒ true, false (readonly)
Returns True if this train has not yet left it’s origin station and started it’s run.
108 109 110 |
# File 'lib/cta_redux/models/train.rb', line 108 def scheduled @scheduled end |
#seconds ⇒ Integer (readonly)
Returns The number of seconds until this train arrives at the next_station.
104 105 106 |
# File 'lib/cta_redux/models/train.rb', line 104 def seconds @seconds end |