Open jbinto opened 9 years ago
This is getting more complicated.
Consider Nextbus::Client.predictions
:
def predictions(agency_id, route_id, stop_id)
response = self.class.do_request("predictions", {"a" => agency_id, "r" => route_id, "s" => stop_id})
response.predictions.direction.prediction
end
When there's 2 or more directions:
> response.predictions.direction.length
=> 2
> response.predictions.direction.class
=> Array
> response.predictions.direction.first.prediction.length
=> 2
> response.predictions.direction.first.prediction.first.epoch_time
=> "1418172993027"
When there's only one direction:
> response.predictions.direction.length
=> 2
> response.predictions.direction.class
=> Hashie::Mash
> response.predictions.direction.first.prediction.length
NoMethodError: undefined method `prediction' for ["title", "West - 504 King towards Dundas West Station via King"]:Array
from (pry):6:in `predictions'
> response.predictions.direction.prediction.length
=> 5
> response.predictions.direction.prediction.first.epoch_time
=> "1418171691675"
In other words:
response.predictions.direction
could be a Hashie::Mash
, or an Array
of Hashie::Mash
.
Shouldn't be the biggest deal ever, but it is a bit annoying.
Summary: Predictions currently don't work:
Details:
It seems that there is a strong assumption in the original
nextbus
code that the following is sufficient for a prediction:Namely, this implies that we don't need a
direction_tag
to get a prediction.The original fixture from the
nextbus
gem for Boston:And the current TTC fixture:
The main difference being that
nextbus
assumes there will only ever be one<direction>
tag inside of<predictions>
.This might take a little bit more work than #1.
"Easiest Thing That Could Possibly Work™": Change the signature of
predictions
to require not only aroute_id
, but adirection_tag
as well. Then we could filter for the specificdirection_tag
. (ed: I have a wicked sense of déjà vu, I feel like I've done this before.)Other considerations:
prediction
object that has an embedded set ofdirection
s?direction
is labelled with a literaltitle
, e.g.West - 504 King towards Dundas West Station via King
which is kinda sucky, but thankfully each individualprediction
has adirTag
e.g.504_1_504
.