From e2cbcdb4dc32db05e2c6d7a7bb57952e1da6dab3 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 23 Mar 2018 17:01:16 +0100 Subject: TomTom::Matrix#points_from_way_costs: Include stop IDs with points We need to persist stop IDs in order to properly construct `WayCost` objects from the costs returned from the TomTom matrix API. In order to persist stop IDs, my idea here is to group together a point and its corresponding ID into a bucket. When we later `#extract_costs_to_way_costs!`, we'll be able to grab the correct ID for a given coordinate to create a `WayCost` from it. Here, we create a new `TomTom::Matrix::Point` class that encapsulates a coordinate and an ID, and build a `Set` of those. I needed an `#eql?` and `#hash` method on `Point` as described in the `Set` documentation (https://ruby-doc.org/stdlib-1.9.3/libdoc/set/rdoc/Set.html) in order to properly maintain a unique set. Refs #6222 --- spec/lib/tom_tom/matrix_spec.rb | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'spec/lib') diff --git a/spec/lib/tom_tom/matrix_spec.rb b/spec/lib/tom_tom/matrix_spec.rb index 257bbd5fd..1cb47752d 100644 --- a/spec/lib/tom_tom/matrix_spec.rb +++ b/spec/lib/tom_tom/matrix_spec.rb @@ -6,20 +6,31 @@ 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: '44-77' ), 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: '77-88' ) ] expect( matrix.points_from_way_costs(way_costs) ).to eq(Set.new([ - Geokit::LatLng.new(48.85086, 2.36143), - Geokit::LatLng.new(47.91231, 1.87606), - Geokit::LatLng.new(52.50867, 13.42879) + TomTom::Matrix::Point.new( + Geokit::LatLng.new(48.85086, 2.36143), + '44' + ), + TomTom::Matrix::Point.new( + Geokit::LatLng.new(47.91231, 1.87606), + '77' + ), + TomTom::Matrix::Point.new( + Geokit::LatLng.new(52.50867, 13.42879), + '88' + ) ])) end end -- cgit v1.2.3