Sha256: bf0ffae92443765e15364a7c21044973a8400bf337bacfcb68c543c9e5bdc12a
Contents?: true
Size: 1.39 KB
Versions: 2
Compression:
Stored size: 1.39 KB
Contents
module StationMaster module Schedule module Find include Ask def find_station_arrivals(station_code, time = nil) MultiJson::load( remote_call(:arrivals, { station_code: station_code, time: format_time(time || Time.now.in_time_zone(TIME_ZONE)) }), symbolize_keys: true) .inject([]) do |array, arrival_hash| array << Arrival.new(arrival_hash) end end def find_station_departures(station_code, time = nil) MultiJson::load( remote_call(:departures, { station_code: station_code, time: format_time(time || Time.now.in_time_zone(TIME_ZONE)) }), symbolize_keys: true) .inject([]) do |array, arrival_hash| array << Departure.new(arrival_hash) end end protected def remote_call(resource, options = {}) request_url = case resource when :arrivals then STATION_MASTER_BASE_URL + "arrivi/#{options[:station_code]}/#{options[:time]}" when :departures then STATION_MASTER_BASE_URL + "partenze/#{options[:station_code]}/#{options[:time]}" else nil end ask!(request_url) if request_url end def format_time(time) time.strftime('%a %b %d %Y %H:%M:%S GMT%z (CET)') end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
station_master-0.1.2 | lib/station_master/schedule/find.rb |
station_master-0.1.1 | lib/station_master/schedule/find.rb |