Class: CTA::BusTracker::PredictionsResponse
- Inherits:
-
API::Response
- Object
- API::Response
- CTA::BusTracker::PredictionsResponse
- Defined in:
- lib/cta_redux/api/bus_tracker.rb
Instance Attribute Summary collapse
-
#predictions ⇒ Array<CTA::Bus::Prediction>
readonly
An array of CTA::Bus::Prediction objects that correspond to the predictions requested.
-
#vehicles ⇒ Array<CTA::Bus>
readonly
An array of CTA::Bus objects that correspond to the predictions requested.
Attributes inherited from API::Response
#error, #parsed_body, #raw_body, #timestamp
Instance Method Summary collapse
-
#initialize(parsed_body, raw_body, debug) ⇒ PredictionsResponse
constructor
A new instance of PredictionsResponse.
Constructor Details
#initialize(parsed_body, raw_body, debug) ⇒ PredictionsResponse
Returns a new instance of PredictionsResponse.
91 92 93 94 95 96 97 98 99 100 |
# File 'lib/cta_redux/api/bus_tracker.rb', line 91 def initialize(parsed_body, raw_body, debug) super(parsed_body, raw_body, debug) @vehicles = Array.wrap(parsed_body["bustime_response"]["prd"]).map do |p| bus = CTA::Bus.find_active_run(p["rt"], p["tmstmp"], (p["dly"] == "true")).first bus.live = CTA::Bus::Live.new(p, p) bus end @predictions = @vehicles.map { |b| b.live.predictions }.flatten end |
Instance Attribute Details
#predictions ⇒ Array<CTA::Bus::Prediction> (readonly)
Returns An array of CTA::Bus::Prediction objects that correspond to the predictions requested. This is equivalent to calling vehicles.map { |b| b.live.predictions }.flatten.
89 90 91 |
# File 'lib/cta_redux/api/bus_tracker.rb', line 89 def predictions @predictions end |