diff options
| -rw-r--r-- | lib/tom_tom/matrix.rb | 16 | ||||
| -rw-r--r-- | lib/tom_tom/matrix/point.rb | 24 | ||||
| -rw-r--r-- | spec/lib/tom_tom/matrix_spec.rb | 21 | 
3 files changed, 54 insertions, 7 deletions
| diff --git a/lib/tom_tom/matrix.rb b/lib/tom_tom/matrix.rb index 985055dae..4ef620f99 100644 --- a/lib/tom_tom/matrix.rb +++ b/lib/tom_tom/matrix.rb @@ -32,8 +32,20 @@ module TomTom        points = Set.new        way_costs.each do |way_cost| -        points.add(way_cost.departure) -        points.add(way_cost.arrival) +        ids = way_cost.id.split('-') + +        points.add( +          TomTom::Matrix::Point.new( +            way_cost.departure, +            ids[0] +          ) +        ) +        points.add( +          TomTom::Matrix::Point.new( +            way_cost.arrival, +            ids[1] +          ) +        )        end        points diff --git a/lib/tom_tom/matrix/point.rb b/lib/tom_tom/matrix/point.rb new file mode 100644 index 000000000..4e9d11e68 --- /dev/null +++ b/lib/tom_tom/matrix/point.rb @@ -0,0 +1,24 @@ +module TomTom +  class Matrix +    class Point +      attr_reader :coordinates, :id + +      def initialize(coordinates, id) +        @coordinates = coordinates +        @id = id +      end + +      def ==(other) +        other.is_a?(self.class) && +          @coordinates == other.coordinates && +          @id == other.id +      end + +      alias :eql? :== + +      def hash +        @coordinates.hash + @id.hash +      end +    end +  end +end 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 | 
