Class: CTA::TrainTracker::FollowResponse

Inherits:
API::Response show all
Defined in:
lib/cta_redux/api/train_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) ⇒ FollowResponse

Returns a new instance of FollowResponse.



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cta_redux/api/train_tracker.rb', line 53

def initialize(parsed_body, raw_body, debug)
  super(parsed_body, raw_body, debug)

  train_info = Array.wrap(parsed_body["ctatt"]["eta"]).first
  @train = CTA::Train.find_active_run(train_info["rn"], self.timestamp, (train_info["isDly"] == "1")).first
  if !@train
    @train = CTA::Train.find_active_run(train_info["rn"], self.timestamp, true).first
  end
  @train.live = CTA::Train::Live.new(parsed_body["ctatt"]["position"], parsed_body["ctatt"]["eta"])
  @predictions = @train.live.predictions
end

Instance Attribute Details

#predictionsArray<CTA::Train::Prediction> (readonly)

Note:

Convenience method, equivalent to calling train.map { |t| t.live.predictions }.flatten

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

Returns:



51
52
53
# File 'lib/cta_redux/api/train_tracker.rb', line 51

def predictions
  @predictions
end

#trainCTA::Train (readonly)

Returns The CTA::Train that corresponds to the train for which you’ve requested follow predictions.

Returns:

  • (CTA::Train)

    The CTA::Train that corresponds to the train for which you’ve requested follow predictions.



48
49
50
# File 'lib/cta_redux/api/train_tracker.rb', line 48

def train
  @train
end