Class: Ratis::ScheduleNearby
- Inherits:
-
Object
- Object
- Ratis::ScheduleNearby
- Defined in:
- lib/ratis/schedule_nearby.rb
Instance Attribute Summary collapse
-
#atstops ⇒ Object
Returns the value of attribute atstops.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#atstops ⇒ Object
Returns the value of attribute atstops.
5 6 7 |
# File 'lib/ratis/schedule_nearby.rb', line 5 def atstops @atstops end |
Class Method Details
.where(conditions) ⇒ Object
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 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/ratis/schedule_nearby.rb', line 7 def self.where(conditions) keys = conditions.keys if keys.include? :latitude raise ArgumentError.new('You must provide longitude') unless keys.include?(:longitude) elsif keys.include? :longitude raise ArgumentError.new('You must provide latitude') unless keys.include?(:latitude) else raise ArgumentError.new('You must provide stop_id') unless keys.include?(:stop_id) end latitude = conditions.delete(:latitude) longitude = conditions.delete(:longitude) date = conditions.delete(:date) time = conditions.delete(:time) window = conditions.delete(:window) walk_distance = conditions.delete(:walk_distance) landmark_id = conditions.delete(:landmark_id) stop_id = conditions.delete(:stop_id) || '' raise ArgumentError.new('You must provide date') unless date raise ArgumentError.new('You must provide time') unless time raise ArgumentError.new('You must provide window') unless window raise ArgumentError.new('You must provide walk_distance') unless walk_distance Ratis.all_conditions_used? conditions response = Request.get 'Schedulenearby', {'Locationlat' => latitude, 'Locationlong' => longitude, 'Date' => date, 'Time' => time, 'Window' => window, 'Walkdist' => walk_distance, 'Landmarkid' => landmark_id, 'Stopid' => stop_id } return [] unless response.success? # TODO: where is this nightmare-ish hash being used? # need to refactor this into something more OO atstops = response.to_array :schedulenearby_response, :atstop atstops.each do |atstop| atstop[:services] = atstop.to_array :service atstop[:services].each do |service| service[:tripinfos] = service.to_array :tripinfo end end schedule_nearby = ScheduleNearby.new schedule_nearby.atstops = atstops.collect { |stop| Hashie::Mash.new stop } schedule_nearby end |
Instance Method Details
#to_hash ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ratis/schedule_nearby.rb', line 64 def to_hash { :atstops => atstops.map do |atstop| { :description => atstop[:description], :walkdist => atstop[:walkdist], :walkdir => atstop[:walkdir], :stopid => atstop[:stopid], :heading => atstop[:heading], :lat => atstop[:lat], :long => atstop[:long], :services => atstop[:services].map do |service| { :route => service[:route], :routetype => service[:routetype], :operator => service[:operator], :sign => service[:sign], :times => service[:times], :trips => service[:tripinfos].map do |tripinfo| { :triptime => tripinfo[:triptime] } end } end } end } end |