Class: CTA::BusTracker::PredictionsResponse

Inherits:
API::Response show all
Defined in:
lib/cta_redux/api/bus_tracker.rb

Instance Attribute Summary collapse

Attributes inherited from API::Response

#error, #parsed_body, #raw_body, #timestamp

Instance Method Summary collapse

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

#predictionsArray<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.

Returns:



89
90
91
# File 'lib/cta_redux/api/bus_tracker.rb', line 89

def predictions
  @predictions
end

#vehiclesArray<CTA::Bus> (readonly)

Returns An array of CTA::Bus objects that correspond to the predictions requested.

Returns:



86
87
88
# File 'lib/cta_redux/api/bus_tracker.rb', line 86

def vehicles
  @vehicles
end