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 parent Stop of this train.
-
#next_stop ⇒ 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.
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/cta_redux/models/train.rb', line 194 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 @next_stop = CTA::Stop.where(:stop_id => (data["stpId"] || data["nextStpId"])).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.
180 181 182 |
# File 'lib/cta_redux/models/train.rb', line 180 def approaching @approaching end |
#arrival_time ⇒ DateTime (readonly)
Returns The time this train is predicted to arrive at the next_station.
174 175 176 |
# File 'lib/cta_redux/models/train.rb', line 174 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.
188 189 190 |
# File 'lib/cta_redux/models/train.rb', line 188 def delayed @delayed end |
#destination ⇒ CTA::Stop (readonly)
Returns The final Stop of this train.
164 165 166 |
# File 'lib/cta_redux/models/train.rb', line 164 def destination @destination end |
#direction ⇒ String (readonly)
Returns A human-readable direction of this train, eg “O’Hare-bound”.
166 167 168 |
# File 'lib/cta_redux/models/train.rb', line 166 def direction @direction end |
#flags ⇒ String (readonly)
Returns Flags for this train. Unused at this time.
190 191 192 |
# File 'lib/cta_redux/models/train.rb', line 190 def flags @flags end |
#minutes ⇒ Integer (readonly)
Returns The number of minutes until this train arrives at the next_station.
176 177 178 |
# File 'lib/cta_redux/models/train.rb', line 176 def minutes @minutes end |
#next_station ⇒ CTA::Stop (readonly)
Returns The next parent Stop of this train.
168 169 170 |
# File 'lib/cta_redux/models/train.rb', line 168 def next_station @next_station end |
#next_stop ⇒ CTA::Stop (readonly)
Returns The next Stop of this train.
170 171 172 |
# File 'lib/cta_redux/models/train.rb', line 170 def next_stop @next_stop end |
#prediction_generated_at ⇒ DateTime (readonly)
Returns The time this CTA::Train::Prediction was generated on the TrainTracker servers.
172 173 174 |
# File 'lib/cta_redux/models/train.rb', line 172 def prediction_generated_at @prediction_generated_at end |
#route ⇒ CTA::Route (readonly)
Returns The Route this train is running.
192 193 194 |
# File 'lib/cta_redux/models/train.rb', line 192 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.
160 161 162 |
# File 'lib/cta_redux/models/train.rb', line 160 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.
182 183 184 |
# File 'lib/cta_redux/models/train.rb', line 182 def scheduled @scheduled end |
#seconds ⇒ Integer (readonly)
Returns The number of seconds until this train arrives at the next_station.
178 179 180 |
# File 'lib/cta_redux/models/train.rb', line 178 def seconds @seconds end |