lib/ratis/timetable.rb in ratis-2.5.2.5 vs lib/ratis/timetable.rb in ratis-2.5.2.6
- old
+ new
@@ -2,19 +2,20 @@
class Timetable
attr_accessor :route_short_name, :direction, :service_type, :operator, :effective, :timepoints, :trips
+ #Ratis::Timetable.where( :route_short_name => "460", :direction => "E", :service_type => 'W')
def self.where(conditions)
short_name = conditions.delete :route_short_name
direction = conditions.delete :direction
date = conditions.delete :date
service_type = conditions.delete :service_type
raise ArgumentError.new('You must provide a route_short_name') unless short_name
raise ArgumentError.new('You must provide a direction') unless direction
- raise ArgumentError.new('You must provide either date or service_type') unless date ^ service_type
+ raise ArgumentError.new('You must provide either date or service_type') if date.blank? && service_type.blank?
Ratis.all_conditions_used? conditions
request_params = { 'Route' => short_name, 'Direction' => direction }
request_params.merge! date ? { 'Date' => date } : { 'Servicetype' => service_type }
@@ -27,17 +28,21 @@
timetable.direction = headway[:direction]
timetable.service_type = headway[:servicetype]
timetable.operator = headway[:operator]
timetable.effective = headway[:effective]
- stop = headway[:timepoints][:stop]
- timetable.timepoints = [ Timetable::Stop.new(stop[:atisstopid], stop[:stopid], stop[:description], stop[:area]) ]
+ timepoints_array = []
+ headway[:timepoints][:stop].each_with_index{|tp, i| timepoints_array.push(Timetable::Stop.new(i, tp[:stopid], tp[:description], tp[:area]) )} rescue []
+ timetable.timepoints = timepoints_array
- trip = headway[:times][:trip]
- timetable.trips = [ Timetable::Trip.new(trip[:time], trip[:comment]) ]
+ trips_array = []
+ headway[:times][:trip].each_with_index{|t,i| trips_array.push(Timetable::Trip.new(i, t[:time], t[:comment]))} rescue []
+ timetable.trips = trips_array
timetable
end
+
+
end
end