Class: CTA::Bus::Prediction
- Inherits:
-
Object
- Object
- CTA::Bus::Prediction
- Defined in:
- lib/cta_redux/models/bus.rb
Instance Attribute Summary collapse
-
#arrival_time ⇒ DateTime
readonly
The time this bus is predicted to arrive or depart.
-
#delayed ⇒ true, false
readonly
True if this bus is considered to be delayed.
-
#direction ⇒ Direction
readonly
The Direction associated with this prediction.
-
#distance ⇒ Integer
readonly
The distance remaining until the bus arrives.
-
#headsign ⇒ String
readonly
The headsign of the bus (final destination, not expressed as Stop).
-
#minutes ⇒ Integer
readonly
The number of minutes until this bus arrives or departs.
-
#prediction_generated_at ⇒ DateTime
readonly
The time this Prediction was generated on the BusTime servers.
-
#route ⇒ CTA::Route
readonly
The Route associated with this prediction.
-
#seconds ⇒ Integer
readonly
The number of seconds until this bus arrives or departs.
-
#stop ⇒ CTA::Stop
readonly
The Stop for this prediction.
-
#type ⇒ String
readonly
The type of prediction, either *A*rrival or *D*eparture.
Instance Method Summary collapse
-
#initialize(data) ⇒ Prediction
constructor
A new instance of Prediction.
Constructor Details
#initialize(data) ⇒ Prediction
Returns a new instance of Prediction.
147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/cta_redux/models/bus.rb', line 147 def initialize(data) @type = data["typ"] @stop = CTA::Stop.where(:stop_id => data["stpid"]).first || CTA::Stop.new_from_api_response(data) @distance = data["dstp"].to_i @route = CTA::Route.where(:route_id => data["rt"]).first @direction = CTA::BusTracker::Direction.new(data["rtdir"]) @headsign = data["des"] @prediction_generated_at = DateTime.parse(data["tmstmp"]) @arrival_time = DateTime.parse(data["prdtm"]) @seconds = @arrival_time.to_time - @prediction_generated_at.to_time @minutes = (@seconds / 60).ceil @delayed = (data["dly"] == "true") end |
Instance Attribute Details
#arrival_time ⇒ DateTime (readonly)
Returns The time this bus is predicted to arrive or depart.
139 140 141 |
# File 'lib/cta_redux/models/bus.rb', line 139 def arrival_time @arrival_time end |
#delayed ⇒ true, false (readonly)
Returns True if this bus is considered to be delayed.
141 142 143 |
# File 'lib/cta_redux/models/bus.rb', line 141 def delayed @delayed end |
#direction ⇒ Direction (readonly)
Returns The Direction associated with this prediction.
133 134 135 |
# File 'lib/cta_redux/models/bus.rb', line 133 def direction @direction end |
#distance ⇒ Integer (readonly)
Returns The distance remaining until the bus arrives.
129 130 131 |
# File 'lib/cta_redux/models/bus.rb', line 129 def distance @distance end |
#headsign ⇒ String (readonly)
Returns The headsign of the bus (final destination, not expressed as Stop).
135 136 137 |
# File 'lib/cta_redux/models/bus.rb', line 135 def headsign @headsign end |
#minutes ⇒ Integer (readonly)
Returns The number of minutes until this bus arrives or departs.
143 144 145 |
# File 'lib/cta_redux/models/bus.rb', line 143 def minutes @minutes end |
#prediction_generated_at ⇒ DateTime (readonly)
Returns The time this CTA::Bus::Prediction was generated on the BusTime servers.
137 138 139 |
# File 'lib/cta_redux/models/bus.rb', line 137 def prediction_generated_at @prediction_generated_at end |
#route ⇒ CTA::Route (readonly)
Returns The Route associated with this prediction.
131 132 133 |
# File 'lib/cta_redux/models/bus.rb', line 131 def route @route end |
#seconds ⇒ Integer (readonly)
Returns The number of seconds until this bus arrives or departs.
145 146 147 |
# File 'lib/cta_redux/models/bus.rb', line 145 def seconds @seconds end |
#stop ⇒ CTA::Stop (readonly)
Returns The Stop for this prediction.
127 128 129 |
# File 'lib/cta_redux/models/bus.rb', line 127 def stop @stop end |
#type ⇒ String (readonly)
Returns The type of prediction, either *A*rrival or *D*eparture.
125 126 127 |
# File 'lib/cta_redux/models/bus.rb', line 125 def type @type end |