Module: MapTP::Parser::Route
- Defined in:
- lib/maptp-service/parser/route.rb
Overview
Parses the results of a calculate route response.
Class Method Summary collapse
-
.to_hash(response) ⇒ Object
Parses the response to a hash and strips all unneccessary data.
Class Method Details
.to_hash(response) ⇒ Object
Parses the response to a hash and strips all unneccessary data
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/maptp-service/parser/route.rb', line 11 def self.to_hash(response) resp = response.to_hash route = resp[:calculate_route_response][:calculate_route_response][:route] output = Hash.new summary = Hash.new summary[:duration] = route[:total_time].to_i summary[:distance] = route[:total_length].to_i output[:summary] = summary directions = Array.new route[:segments][:item].each do |direction| direction.delete(:type) direction.delete(:descriptions) direction[:start].delete(:type) direction[:start][:lng] = direction[:start][:longitude].to_f / 60 direction[:start].delete(:longitude) direction[:start][:lat] = direction[:start][:latitude].to_f / 60 direction[:start].delete(:latitude) direction[:heading] = direction[:direction][:value].to_i direction.delete(:direction) if direction[:coordinates] direction[:path] = {} direction[:path][:lng] = direction[:coordinates][:longitudes].split("|").map { |item| item.to_f / 60 } direction[:path][:lat] = direction[:coordinates][:latitudes].split("|").map { |item| item.to_f / 60 } direction.delete(:coordinates) end if direction[:roundabout_exit_number] direction[:roundabout_exit_number] = direction[:roundabout_exit_number].to_i end if direction[:exit_number] direction[:exit_number] = direction[:exit_number].to_i end # really?! direction.delete(:via) direction[:duration] = direction[:time].to_i direction.delete(:time) direction[:distance] = direction[:segment_length].to_i direction.delete(:segment_length) directions << direction end output[:directions] = directions output end |