Class: Routing::Parser::HereSimple
- Inherits:
-
Object
- Object
- Routing::Parser::HereSimple
- Defined in:
- lib/routing/parser/here_simple.rb
Overview
A very simple parser implementation for a Nokia Here Routing Service v7. It converts the json response of the routing service to an Array of GeoPoints.
Instance Method Summary collapse
-
#initialize(response) ⇒ HereSimple
constructor
Creates a new instance of the parser.
-
#to_geo_points ⇒ Array<GeoPoint>
Converts the server response in an Array of GeoPoints.
Constructor Details
#initialize(response) ⇒ HereSimple
Creates a new instance of the parser.
12 13 14 15 16 17 18 19 20 |
# File 'lib/routing/parser/here_simple.rb', line 12 def initialize(response) response = JSON.parse(response) check_for_error(response) @route = response["response"]["route"].first @waypoints = @route["waypoint"].dup @overall_covered_distance = 0 @overall_relative_time = 0 end |
Instance Method Details
#to_geo_points ⇒ Array<GeoPoint>
Converts the server response in an Array of GeoPoints
26 27 28 29 30 31 32 33 |
# File 'lib/routing/parser/here_simple.rb', line 26 def to_geo_points legs = @route["leg"] geo_points = legs.map { |leg| parse_leg(leg) }.flatten # At last we add the destination point geo_points << parse_maneuver(legs.last["maneuver"].last, waypoint: true) geo_points end |