Class: Ratis::ClosestStop

Inherits:
Object
  • Object
show all
Defined in:
lib/ratis/closest_stop.rb

Class Method Summary collapse

Class Method Details

.where(conditions) ⇒ Object

Raises:

  • (ArgumentError)


4
5
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
# File 'lib/ratis/closest_stop.rb', line 4

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