af83/chouette-core

View on GitHub
app/lib/tom_tom/matrix/request_json_serializer.rb

Summary

Maintainability
A
0 mins
Test Coverage
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