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.



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

#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



106
107
108
# File 'lib/cta_redux/models/train.rb', line 106

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



100
101
102
# File 'lib/cta_redux/models/train.rb', line 100

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



114
115
116
# File 'lib/cta_redux/models/train.rb', line 114

def delayed
  @delayed
end

#destinationCTA::Stop (readonly)

Returns The final Stop of this train.

Returns:



92
93
94
# File 'lib/cta_redux/models/train.rb', line 92

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”



94
95
96
# File 'lib/cta_redux/models/train.rb', line 94

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.



116
117
118
# File 'lib/cta_redux/models/train.rb', line 116

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



102
103
104
# File 'lib/cta_redux/models/train.rb', line 102

def minutes
  @minutes
end

#next_stationCTA::Stop (readonly)

Returns The next Stop of this train.

Returns:



96
97
98
# File 'lib/cta_redux/models/train.rb', line 96

def next_station
  @next_station
end

#prediction_generated_atDateTime (readonly)

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

Returns:



98
99
100
# File 'lib/cta_redux/models/train.rb', line 98

def prediction_generated_at
  @prediction_generated_at
end

#routeCTA::Route (readonly)

Returns The Route this train is running.

Returns:



118
119
120
# File 'lib/cta_redux/models/train.rb', line 118

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.



88
89
90
# File 'lib/cta_redux/models/train.rb', line 88

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



108
109
110
# File 'lib/cta_redux/models/train.rb', line 108

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



104
105
106
# File 'lib/cta_redux/models/train.rb', line 104

def seconds
  @seconds
end

#tripCTA::Trip (readonly)

Returns The CTA::Trip associated with this train.

Returns:



90
91
92
# File 'lib/cta_redux/models/train.rb', line 90

def trip
  @trip
end