Class: CTA::TrainTracker::ArrivalsResponse
- Inherits:
-
API::Response
- Object
- API::Response
- CTA::TrainTracker::ArrivalsResponse
- Defined in:
- lib/cta_redux/api/train_tracker.rb
Instance Attribute Summary collapse
-
#predictions ⇒ Array<CTA::Train::Prediction>
readonly
An array of CTA::Train::Prediction objects that correspond to the predictions requested.
-
#routes ⇒ Array<CTA::Route>
readonly
An array of Route objects that correspond to the predictions requested.
-
#trains ⇒ Array<CTA::Train>
readonly
An array of CTA::Train 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) ⇒ ArrivalsResponse
constructor
A new instance of ArrivalsResponse.
Constructor Details
#initialize(parsed_body, raw_body, debug) ⇒ ArrivalsResponse
Returns a new instance of ArrivalsResponse.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/cta_redux/api/train_tracker.rb', line 13 def initialize(parsed_body, raw_body, debug) super(parsed_body, raw_body, debug) eta_map = Array.wrap(parsed_body["ctatt"]["eta"]).inject({}) do |h, eta| h[eta["rt"]] ||= [] h[eta["rt"]] << eta h end @routes = eta_map.map do |rt, etas| trains = etas.map do |t| train = CTA::Train.find_active_run(t["rn"], self., (t["isDly"] == "1")).first if !train train = CTA::Train.find_active_run(t["rn"], self., true).first end position = t.select { |k,v| ["lat", "lon", "heading"].include?(k) } train.live = CTA::Train::Live.new(position, t) train end route = CTA::Route.where(:route_id => rt.capitalize).first route.live = CTA::Route::Live.new(trains) route end @trains = @routes.map { |r| r.live.vehicles }.flatten @predictions = @trains.map { |t| t.live.predictions }.flatten end |
Instance Attribute Details
#predictions ⇒ Array<CTA::Train::Prediction> (readonly)
Convenience method, equivalent to calling trains.map { |t| t.live.predictions }.flatten
Returns An array of CTA::Train::Prediction objects that correspond to the predictions requested.
11 12 13 |
# File 'lib/cta_redux/api/train_tracker.rb', line 11 def predictions @predictions end |
#routes ⇒ Array<CTA::Route> (readonly)
Returns An array of Route objects that correspond to the predictions requested.
5 6 7 |
# File 'lib/cta_redux/api/train_tracker.rb', line 5 def routes @routes end |
#trains ⇒ Array<CTA::Train> (readonly)
Convenience method, equivalent to calling routes.map { |r| r.vehicles }.flatten
Returns An array of CTA::Train objects that correspond to the predictions requested.
8 9 10 |
# File 'lib/cta_redux/api/train_tracker.rb', line 8 def trains @trains end |