lib/muni/stop.rb in muni-0.0.4 vs lib/muni/stop.rb in muni-0.0.5

- old
+ new

@@ -3,12 +3,23 @@ module Muni class Stop < Base def predictions stop = Stop.send(:fetch, :predictions, r: route_tag, d: direction, s: tag) - return [] unless stop && stop['predictions'] - stop['predictions'].first['direction'].first['prediction'].collect do |pred| + available_predictions(stop).collect do |pred| Prediction.new(pred) end end + + private + + def available_predictions(stop) + return [] unless stop && + stop['predictions'] && + stop['predictions'].first['direction'] && + stop['predictions'].first['direction'].first['prediction'] + + stop['predictions'].first['direction'].first['prediction'] + end + end end