Class: Ratis::Timetable
- Inherits:
-
Object
- Object
- Ratis::Timetable
- Defined in:
- lib/ratis/timetable.rb
Defined Under Namespace
Instance Attribute Summary collapse
-
#direction ⇒ Object
Returns the value of attribute direction.
-
#effective ⇒ Object
Returns the value of attribute effective.
-
#operator ⇒ Object
Returns the value of attribute operator.
-
#route_short_name ⇒ Object
Returns the value of attribute route_short_name.
-
#service_type ⇒ Object
Returns the value of attribute service_type.
-
#timepoints ⇒ Object
Returns the value of attribute timepoints.
-
#trips ⇒ Object
Returns the value of attribute trips.
Class Method Summary collapse
Instance Attribute Details
#direction ⇒ Object
Returns the value of attribute direction.
4 5 6 |
# File 'lib/ratis/timetable.rb', line 4 def direction @direction end |
#effective ⇒ Object
Returns the value of attribute effective.
4 5 6 |
# File 'lib/ratis/timetable.rb', line 4 def effective @effective end |
#operator ⇒ Object
Returns the value of attribute operator.
4 5 6 |
# File 'lib/ratis/timetable.rb', line 4 def operator @operator end |
#route_short_name ⇒ Object
Returns the value of attribute route_short_name.
4 5 6 |
# File 'lib/ratis/timetable.rb', line 4 def route_short_name @route_short_name end |
#service_type ⇒ Object
Returns the value of attribute service_type.
4 5 6 |
# File 'lib/ratis/timetable.rb', line 4 def service_type @service_type end |
#timepoints ⇒ Object
Returns the value of attribute timepoints.
4 5 6 |
# File 'lib/ratis/timetable.rb', line 4 def timepoints @timepoints end |
#trips ⇒ Object
Returns the value of attribute trips.
4 5 6 |
# File 'lib/ratis/timetable.rb', line 4 def trips @trips end |
Class Method Details
.where(conditions) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ratis/timetable.rb', line 6 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') 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 } response = Request.get 'Timetable', request_params return nil unless response.success? headway = response.to_hash[:timetable_response][:headway] = Timetable.new .route_short_name = headway[:route] .direction = headway[:direction] .service_type = headway[:servicetype] .operator = headway[:operator] .effective = headway[:effective] timepoints_array = [] headway[:timepoints][:stop].each_with_index do |tp, i| timepoints_array << Timetable::Stop.new(i, tp[:atisstopid], tp[:stopid], tp[:description], tp[:area]) end rescue [] .timepoints = timepoints_array trips_array = [] headway[:times][:trip].each_with_index do |t,i| trips_array << Timetable::Trip.new(i, t[:time], t[:comment]) end rescue [] .trips = trips_array end |