diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/way_cost_collection_json_serializer.rb | 16 | 
1 files changed, 16 insertions, 0 deletions
| 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 | 
