aboutsummaryrefslogtreecommitdiffstats
path: root/lib/tom_tom/matrix
diff options
context:
space:
mode:
Diffstat (limited to 'lib/tom_tom/matrix')
-rw-r--r--lib/tom_tom/matrix/point.rb18
-rw-r--r--lib/tom_tom/matrix/request_json_serializer.rb25
2 files changed, 43 insertions, 0 deletions
diff --git a/lib/tom_tom/matrix/point.rb b/lib/tom_tom/matrix/point.rb
new file mode 100644
index 000000000..435b4d4b0
--- /dev/null
+++ b/lib/tom_tom/matrix/point.rb
@@ -0,0 +1,18 @@
+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
+ end
+ end
+end
diff --git a/lib/tom_tom/matrix/request_json_serializer.rb b/lib/tom_tom/matrix/request_json_serializer.rb
new file mode 100644
index 000000000..f4d12e482
--- /dev/null
+++ b/lib/tom_tom/matrix/request_json_serializer.rb
@@ -0,0 +1,25 @@
+module TomTom
+ class Matrix
+ class RequestJSONSerializer
+ def self.dump(hash)
+ hash[:origins].map! do |point|
+ point_to_f(point)
+ end
+ hash[:destinations].map! do |point|
+ point_to_f(point)
+ end
+
+ JSON.dump(hash)
+ end
+
+ private
+
+ def self.point_to_f(point)
+ point[:point][:latitude] = point[:point][:latitude].to_f
+ point[:point][:longitude] = point[:point][:longitude].to_f
+
+ point
+ end
+ end
+ end
+end