Class: Ratis::Walkstop

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Walkstop

Returns a new instance of Walkstop.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/ratis/walkstop.rb', line 9

def initialize(response)
  @success = response.success?
  @legs    = []

  if @success
    walkstop_response = response[:walkstop_response]
    @legs          = response.to_array(:walkstop_response, :walk, :leg)
    @walk_distance = walkstop_response[:walkinfo][:walkdistance]
    @walk_units    = walkstop_response[:walkinfo][:walkunits]
    @walk_time     = walkstop_response[:walkinfo][:walktime]
    @start_text    = walkstop_response[:starttext]
    @end_text      = walkstop_response[:endtext]
  end
end

Instance Attribute Details

#end_latObject

Returns the value of attribute end_lat.



5
6
7
# File 'lib/ratis/walkstop.rb', line 5

def end_lat
  @end_lat
end

#end_longObject

Returns the value of attribute end_long.



5
6
7
# File 'lib/ratis/walkstop.rb', line 5

def end_long
  @end_long
end

#end_textObject

Returns the value of attribute end_text.



5
6
7
# File 'lib/ratis/walkstop.rb', line 5

def end_text
  @end_text
end

#legsObject

Returns the value of attribute legs.



5
6
7
# File 'lib/ratis/walkstop.rb', line 5

def legs
  @legs
end

#start_latObject

Returns the value of attribute start_lat.



5
6
7
# File 'lib/ratis/walkstop.rb', line 5

def start_lat
  @start_lat
end

#start_longObject

Returns the value of attribute start_long.



5
6
7
# File 'lib/ratis/walkstop.rb', line 5

def start_long
  @start_long
end

#start_textObject

Returns the value of attribute start_text.



5
6
7
# File 'lib/ratis/walkstop.rb', line 5

def start_text
  @start_text
end

#successObject

Returns the value of attribute success.



5
6
7
# File 'lib/ratis/walkstop.rb', line 5

def success
  @success
end

#walk_distanceObject

Returns the value of attribute walk_distance.



5
6
7
# File 'lib/ratis/walkstop.rb', line 5

def walk_distance
  @walk_distance
end

#walk_timeObject

Returns the value of attribute walk_time.



5
6
7
# File 'lib/ratis/walkstop.rb', line 5

def walk_time
  @walk_time
end

#walk_unitsObject

Returns the value of attribute walk_units.



5
6
7
# File 'lib/ratis/walkstop.rb', line 5

def walk_units
  @walk_units
end

Class Method Details

.where(conditions) ⇒ Object

Raises:

  • (ArgumentError)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ratis/walkstop.rb', line 24

def self.where(conditions)
  start_lat  = conditions.delete :start_lat
  start_long = conditions.delete :start_long
  end_lat    = conditions.delete :end_lat
  end_long   = conditions.delete :end_long

  raise ArgumentError.new('You must provide a start_lat') unless start_lat
  raise ArgumentError.new('You must provide a start_long') unless start_long
  raise ArgumentError.new('You must provide an end_lat') unless end_lat
  raise ArgumentError.new('You must provide an end_long') unless end_long

  Ratis.all_conditions_used? conditions

  response = Request.get 'Walkstop',
                         'Startlat'  => start_lat,
                         'Startlong' => start_long,
                         'Endlat'    => end_lat,
                         'Endlong'   => end_long

  Walkstop.new(response)
end

Instance Method Details

#to_hashObject



46
47
48
49
# File 'lib/ratis/walkstop.rb', line 46

def to_hash
  keys = [:legs, :walk_distance, :walk_units, :walk_time]
  Hash[keys.map { |k| [k, send(k)] }]
end