Class: CTA::Train::Prediction

Inherits:
Object
  • Object
show all
Defined in:
lib/cta_redux/models/train.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#approachingtrue, false (readonly)

Returns True if this train is considered to be ‘approaching’ the next_station by the CTA.

Returns:

  • (true, false)

    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_timeDateTime (readonly)

Returns The time this train is predicted to arrive at the next_station.

Returns:

  • (DateTime)

    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

#delayedtrue, false (readonly)

Note:

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.

Returns:

  • (true, false)

    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

#destinationCTA::Stop (readonly)

Returns The final Stop of this train.

Returns:



164
165
166
# File 'lib/cta_redux/models/train.rb', line 164

def destination
  @destination
end

#directionString (readonly)

Returns A human-readable direction of this train, eg “O’Hare-bound”.

Returns:

  • (String)

    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

#flagsString (readonly)

Returns Flags for this train. Unused at this time.

Returns:

  • (String)

    Flags for this train. Unused at this time.



190
191
192
# File 'lib/cta_redux/models/train.rb', line 190

def flags
  @flags
end

#minutesInteger (readonly)

Returns The number of minutes until this train arrives at the next_station.

Returns:

  • (Integer)

    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_stationCTA::Stop (readonly)

Returns The next parent Stop of this train.

Returns:



168
169
170
# File 'lib/cta_redux/models/train.rb', line 168

def next_station
  @next_station
end

#next_stopCTA::Stop (readonly)

Returns The next Stop of this train.

Returns:



170
171
172
# File 'lib/cta_redux/models/train.rb', line 170

def next_stop
  @next_stop
end

#prediction_generated_atDateTime (readonly)

Returns The time this CTA::Train::Prediction was generated on the TrainTracker servers.

Returns:



172
173
174
# File 'lib/cta_redux/models/train.rb', line 172

def prediction_generated_at
  @prediction_generated_at
end

#routeCTA::Route (readonly)

Returns The Route this train is running.

Returns:



192
193
194
# File 'lib/cta_redux/models/train.rb', line 192

def route
  @route
end

#runString (readonly)

Note:

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.

Returns:

  • (String)

    The run identifier for this train.



160
161
162
# File 'lib/cta_redux/models/train.rb', line 160

def run
  @run
end

#scheduledtrue, false (readonly)

Returns True if this train has not yet left it’s origin station and started it’s run.

Returns:

  • (true, false)

    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

#secondsInteger (readonly)

Returns The number of seconds until this train arrives at the next_station.

Returns:

  • (Integer)

    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

#tripCTA::Trip (readonly)

Returns The CTA::Trip associated with this train.

Returns:



162
163
164
# File 'lib/cta_redux/models/train.rb', line 162

def trip
  @trip
end