From 11894d94b6698590a9ddb37729fdd90ea081159d Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 13 Mar 2018 12:04:19 +0100 Subject: Add `WayCostCollectionJSONSerializer` A JSON serialiser for a collection of `WayCost`s. This will be used to store `WayCost`s for a `Chouette::Route` in the `Route#costs` JSON field. Refs #6095 --- lib/way_cost_collection_json_serializer.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 lib/way_cost_collection_json_serializer.rb (limited to 'lib') diff --git a/lib/way_cost_collection_json_serializer.rb b/lib/way_cost_collection_json_serializer.rb new file mode 100644 index 000000000..191871cca --- /dev/null +++ b/lib/way_cost_collection_json_serializer.rb @@ -0,0 +1,16 @@ +class WayCostCollectionJSONSerializer + def self.dump(way_costs) + return if way_costs.nil? + + costs_by_id = {} + + way_costs.each do |way_cost| + costs_by_id[way_cost.id] = { + distance: way_cost.distance, + time: way_cost.time + } + end + + JSON.dump(costs_by_id) + end +end -- cgit v1.2.3