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.
110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/cta_redux/models/bus.rb', line 110 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.
102 103 104 |
# File 'lib/cta_redux/models/bus.rb', line 102 def arrival_time @arrival_time end |
#delayed ⇒ true, false (readonly)
Returns True if this bus is considered to be delayed.
104 105 106 |
# File 'lib/cta_redux/models/bus.rb', line 104 def delayed @delayed end |
#direction ⇒ Direction (readonly)
Returns The Direction associated with this prediction.
96 97 98 |
# File 'lib/cta_redux/models/bus.rb', line 96 def direction @direction end |
#distance ⇒ Integer (readonly)
Returns The distance remaining until the bus arrives.
92 93 94 |
# File 'lib/cta_redux/models/bus.rb', line 92 def distance @distance end |
#headsign ⇒ String (readonly)
Returns The headsign of the bus (final destination, not expressed as Stop).
98 99 100 |
# File 'lib/cta_redux/models/bus.rb', line 98 def headsign @headsign end |
#minutes ⇒ Integer (readonly)
Returns The number of minutes until this bus arrives or departs.
106 107 108 |
# File 'lib/cta_redux/models/bus.rb', line 106 def minutes @minutes end |
#prediction_generated_at ⇒ DateTime (readonly)
Returns The time this CTA::Bus::Prediction was generated on the BusTime servers.
100 101 102 |
# File 'lib/cta_redux/models/bus.rb', line 100 def prediction_generated_at @prediction_generated_at end |
#route ⇒ CTA::Route (readonly)
Returns The Route associated with this prediction.
94 95 96 |
# File 'lib/cta_redux/models/bus.rb', line 94 def route @route end |
#seconds ⇒ Integer (readonly)
Returns The number of seconds until this bus arrives or departs.
108 109 110 |
# File 'lib/cta_redux/models/bus.rb', line 108 def seconds @seconds end |
#stop ⇒ CTA::Stop (readonly)
Returns The Stop for this prediction.
90 91 92 |
# File 'lib/cta_redux/models/bus.rb', line 90 def stop @stop end |
#type ⇒ String (readonly)
Returns The type of prediction, either *A*rrival or *D*eparture.
88 89 90 |
# File 'lib/cta_redux/models/bus.rb', line 88 def type @type end |