Sha256: 2c6535d4e682f6bf721dbdba65675f5140b8b5f7d82c134600f9da8d54c06fc8

Contents?: true

Size: 1.57 KB

Versions: 19

Compression:

Stored size: 1.57 KB

Contents

module Ratis
  class ClosestStop

    def self.where(conditions)
      latitude      = conditions.delete :latitude
      longitude     = conditions.delete :longitude
      location_text = conditions.delete :location_text
      num_stops     = conditions.delete :num_stops

      raise ArgumentError.new('You must provide a longitude') unless longitude
      raise ArgumentError.new('You must provide a latitude')  unless latitude

      Ratis.all_conditions_used? conditions

      response = Request.get 'Closeststop',
                             {'Locationlat'  => latitude,
                              'Locationlong' => longitude,
                              'Locationtext' => location_text,
                              'Numstops'     => num_stops }

      return [] unless response.success?

      stops = response.to_hash[:closeststop_response][:stops][:stop].map do |arr|
                next if arr[:description].blank?

                stop = Ratis::Stop.new
                stop.walk_dist     = arr[:walkdist]
                stop.description   = arr[:description]
                stop.stop_id       = arr[:stopid]
                stop.atis_stop_id  = arr[:atisstopid]
                stop.latitude      = arr[:lat]
                stop.longitude     = arr[:long]
                stop.walk_dir      = arr[:walkdir]
                stop.side          = arr[:side]
                stop.heading       = arr[:heading]
                stop.stop_position = arr[:stopposition]
                stop.route_dirs    = arr[:routedirs]
                stop

              end.compact

    end

  end

end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
ratis-3.3.5 lib/ratis/closest_stop.rb
ratis-3.3.4 lib/ratis/closest_stop.rb
ratis-3.3.3 lib/ratis/closest_stop.rb
ratis-3.3.2 lib/ratis/closest_stop.rb
ratis-3.3.1 lib/ratis/closest_stop.rb
ratis-3.3.0 lib/ratis/closest_stop.rb
ratis-3.2.1 lib/ratis/closest_stop.rb
ratis-3.2.0 lib/ratis/closest_stop.rb
ratis-3.1.8 lib/ratis/closest_stop.rb
ratis-3.1.7 lib/ratis/closest_stop.rb
ratis-3.1.6 lib/ratis/closest_stop.rb
ratis-3.1.5.1 lib/ratis/closest_stop.rb
ratis-3.1.5 lib/ratis/closest_stop.rb
ratis-3.1.4 lib/ratis/closest_stop.rb
ratis-3.1.3 lib/ratis/closest_stop.rb
ratis-3.1.2 lib/ratis/closest_stop.rb
ratis-3.1.1 lib/ratis/closest_stop.rb
ratis-3.1.0 lib/ratis/closest_stop.rb
ratis-3.0.0 lib/ratis/closest_stop.rb