diff options
| -rw-r--r-- | lib/tom_tom/matrix.rb | 18 | ||||
| -rw-r--r-- | spec/lib/tom_tom/matrix_spec.rb | 29 | 
2 files changed, 28 insertions, 19 deletions
| diff --git a/lib/tom_tom/matrix.rb b/lib/tom_tom/matrix.rb index e0ee566b6..55568ab66 100644 --- a/lib/tom_tom/matrix.rb +++ b/lib/tom_tom/matrix.rb @@ -5,8 +5,8 @@ module TomTom      end      def matrix(way_costs) -      points = points_from_way_costs(way_costs) -      points = points_as_params(points) +      points_with_ids = points_from_way_costs(way_costs) +      points = points_as_params(points_with_ids)        response = @connection.post do |req|          req.url '/routing/1/matrix/json' @@ -23,7 +23,7 @@ module TomTom        extract_costs_to_way_costs!(          way_costs, -        points, +        points_with_ids,          JSON.parse(response.body)        )      end @@ -81,16 +81,16 @@ module TomTom            way_costs << WayCost.new(              departure: Geokit::LatLng.new( -              departure[:point][:latitude], -              departure[:point][:longitude] +              departure.coordinates.lat, +              departure.coordinates.lng              ),              arrival: Geokit::LatLng.new( -              arrival[:point][:latitude], -              arrival[:point][:longitude] +              arrival.coordinates.lat, +              arrival.coordinates.lng              ),              distance: distance, -            time: column['response']['routeSummary']['travelTimeInSeconds'] -            # id: 'TODO: figure out how to add combined stop IDs' +            time: column['response']['routeSummary']['travelTimeInSeconds'], +            id: "#{departure.id}-#{arrival.id}"            )          end        end diff --git a/spec/lib/tom_tom/matrix_spec.rb b/spec/lib/tom_tom/matrix_spec.rb index b27d99a64..e67e539b7 100644 --- a/spec/lib/tom_tom/matrix_spec.rb +++ b/spec/lib/tom_tom/matrix_spec.rb @@ -82,11 +82,13 @@ RSpec.describe TomTom::Matrix do        way_costs = [          WayCost.new(            departure: Geokit::LatLng.new(48.85086, 2.36143), -          arrival: Geokit::LatLng.new(47.91231, 1.87606) +          arrival: Geokit::LatLng.new(47.91231, 1.87606), +          id: '55-99'          ),          WayCost.new(            departure: Geokit::LatLng.new(47.91231, 1.87606), -          arrival: Geokit::LatLng.new(52.50867, 13.42879) +          arrival: Geokit::LatLng.new(52.50867, 13.42879), +          id: '99-22'          )        ] @@ -95,49 +97,56 @@ RSpec.describe TomTom::Matrix do            departure: Geokit::LatLng.new(48.85086, 2.36143),            arrival: Geokit::LatLng.new(47.91231, 1.87606),            distance: 117947, -          time: 8356 +          time: 8356, +          id: '55-99'          ),          WayCost.new(            departure: Geokit::LatLng.new(48.85086, 2.36143),            arrival: Geokit::LatLng.new(52.50867, 13.42879),            distance: 999088, -          time: 62653 +          time: 62653, +          id: '55-22'          ),          WayCost.new(            departure: Geokit::LatLng.new(47.91231, 1.87606),            arrival: Geokit::LatLng.new(48.85086, 2.36143),            distance: 117231, -          time: 9729 +          time: 9729, +          id: '99-55'          ),          WayCost.new(            departure: Geokit::LatLng.new(47.91231, 1.87606),            arrival: Geokit::LatLng.new(52.50867, 13.42879),            distance: 1114635, -          time: 72079 +          time: 72079, +          id: '99-22'          ),          WayCost.new(            departure: Geokit::LatLng.new(52.50867, 13.42879),            arrival: Geokit::LatLng.new(48.85086, 2.36143),            distance: 997232, -          time: 63245 +          time: 63245, +          id: '22-55'          ),          WayCost.new(            departure: Geokit::LatLng.new(52.50867, 13.42879),            arrival: Geokit::LatLng.new(47.91231, 1.87606),            distance: 1113108, -          time: 68485 +          time: 68485, +          id: '22-99'          ),          WayCost.new(            departure: Geokit::LatLng.new(52.50867, 13.42879),            arrival: Geokit::LatLng.new(52.50867, 13.42879),            distance: 344, -          time: 109 +          time: 109, +          id: '22-22'          )        ]        matrix_response = JSON.parse(read_fixture('tom_tom_matrix.json')) -      points = matrix.points_as_params(matrix.points_from_way_costs(way_costs)) +      points = matrix.points_from_way_costs(way_costs)        expect(          matrix.extract_costs_to_way_costs!(way_costs, points, matrix_response) | 
