aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/route_way_cost_json_serializer.rb22
1 files changed, 22 insertions, 0 deletions
diff --git a/lib/route_way_cost_json_serializer.rb b/lib/route_way_cost_json_serializer.rb
new file mode 100644
index 000000000..20b3d6ee2
--- /dev/null
+++ b/lib/route_way_cost_json_serializer.rb
@@ -0,0 +1,22 @@
+class RouteWayCostJSONSerializer
+ def self.dump(way_costs)
+ return if way_costs.nil?
+
+ way_costs.each do |_, costs|
+ costs['distance'] = self.meters_to_kilometers(costs['distance'])
+ costs['time'] = self.seconds_to_minutes(costs['time'])
+ end
+
+ JSON.dump(way_costs)
+ end
+
+ private
+
+ def self.meters_to_kilometers(num)
+ num / 1000.0
+ end
+
+ def self.seconds_to_minutes(num)
+ num / 60
+ end
+end