lib/ratis/next_bus.rb in ratis-3.1.4 vs lib/ratis/next_bus.rb in ratis-3.1.5
- old
+ new
@@ -3,31 +3,41 @@
class NextBus
attr_accessor :stop, :services, :success
def initialize(response)
- @success = response.success?
- @stop = response.body[:nextbus_response][:atstop]
- _services = @stop.delete(:service)
+ @success = response.success?
- unless _services.is_a?(Array)
- _services = [_services]
- end
+ if @success
+ @stop = response.body[:nextbus_response][:atstop]
- @services = _services.map do |service|
- OpenStruct.new(:status => service[:status],
- :sign => service[:sign],
- :routetype => service[:routetype],
- :times => service[:times],
- :direction => service[:direction],
- :servicetype => service[:servicetype],
- :route => service[:route],
- :operator => service[:operator],
- :trips => parse_trip_info(service[:tripinfo])
- )
+ _services = @stop.delete(:service)
+
+ unless _services.is_a?(Array)
+ _services = [_services]
+ end
+
+ @services = _services.map do |service|
+ OpenStruct.new(:status => service[:status],
+ :sign => service[:sign],
+ :routetype => service[:routetype],
+ :times => service[:times],
+ :direction => service[:direction],
+ :servicetype => service[:servicetype],
+ :route => service[:route],
+ :operator => service[:operator],
+ :trips => parse_trip_info(service[:tripinfo])
+ )
+ end
+
+ else
+ @stop = {}
+ @services = []
end
+ debugger
+ x = 1
end
def parse_trip_info(trips)
# can come back as an Array or single Hash...
if trips.is_a?(Array)
@@ -75,10 +85,10 @@
Ratis.all_conditions_used?(conditions)
response = Request.get 'Nextbus', {'Stopid' => stop_id,
'Appid' => app_id,
'Date' => datetime.strftime("%m/%d/%Y"),
- 'Time' => datetime.strftime("%I%M"),
+ 'Time' => datetime.strftime("%H%M"),
'Type' => type }
NextBus.new(response)
end