module SunbusTimes
Public Instance Methods
Source
# File lib/sunbus/times.rb, line 36 def lookup(query, region: SunbusConfig::DEFAULT_REGION, fetch: nil, time: Time.now, limit: SunbusConfig::MAX_DEPARTURES) candidates = stop_candidates(query, region: region, fetch: fetch) return { error: "Stop not found — try !sunbus stop #{query}" } if candidates.empty? SunbusDayLookup.each_service_day(time) do |lookup_time, day_offset| candidates.each do |stop| rows = SunbusGtfs.departures_at_stop(stop, region: region, fetch: fetch, time: lookup_time, limit: limit) next if rows.empty? return { stop: stop, rows: rows, service_date: SunbusGtfs.local_date(lookup_time), day_offset: day_offset } end end { stop: candidates.first, rows: [], service_date: SunbusGtfs.local_date(time), day_offset: 0 } end
Source
# File lib/sunbus/times.rb, line 16 def stop_candidates(query, region:, fetch:) primary = SunbusGtfs.find_stop(query, region: region, fetch: fetch) candidates = [] candidates << primary if primary SunbusGtfs.search_stops(query, region: region, fetch: fetch, limit: SunbusConfig::MAX_SUBURB_STOPS).each do |stop| candidates << stop unless candidates.any? { |row| row[:stop_id] == stop[:stop_id] } end return candidates unless SunbusSuburbs.resolve(query, region: region) suburb = SunbusGtfs.stops_for_suburb(query, region: region, fetch: fetch) return candidates if suburb[:error] suburb[:stops].each do |stop| candidates << stop unless candidates.any? { |row| row[:stop_id] == stop[:stop_id] } end candidates end