Sha256: b3d12ab59bc4e0b57d851e51c6f477441b8f9ddbc0dd42cf6e0ec21f9657d2d2

Contents?: true

Size: 1.37 KB

Versions: 27

Compression:

Stored size: 1.37 KB

Contents

module Ratis

  class Walk

    attr_accessor :legs, :walk_distance, :walk_units, :walk_time

    def self.walk_stop(conditions)
      start_latitude = conditions.delete :start_latitude
      start_longitude = conditions.delete :start_longitude
      end_latitude = conditions.delete :end_latitude
      end_longitude = conditions.delete :end_longitude

      raise ArgumentError.new('You must provide a start_latitude') unless start_latitude
      raise ArgumentError.new('You must provide a start_longitude') unless start_longitude
      raise ArgumentError.new('You must provide an end_latitude') unless end_latitude
      raise ArgumentError.new('You must provide an end_longitude') unless end_longitude

      response = Request.get 'Walkstop', 'Startlat' => start_latitude, 'Startlong' => start_longitude, 'Endlat' => end_latitude, 'Endlong' => end_longitude
      return nil unless response.success?

      response_walk = response[:walkstop_response]

      walk = Walk.new
      walk.legs = response_walk[:walk][:leg].map {|l| { :description => l } }
      walk.walk_distance = response_walk[:walkinfo][:walkdistance]
      walk.walk_units = response_walk[:walkinfo][:walkunits]
      walk.walk_time = response_walk[:walkinfo][:walktime]
      walk
    end

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

end

Version data entries

27 entries across 27 versions & 1 rubygems

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