diff options
| author | Alban Peignier | 2018-03-15 18:27:41 +0100 |
|---|---|---|
| committer | GitHub | 2018-03-15 18:27:41 +0100 |
| commit | 90ae17c0d0f626763f456f061c472a66ec06eef1 (patch) | |
| tree | fb97b63dc1f7c8be98b5cbce40c06ce693641b45 /lib | |
| parent | f011f7e9806ffeaaba3ad73510bc818211f55dbd (diff) | |
| parent | dd8b4cc13d8e052d0fac7a25569f869470198256 (diff) | |
| download | chouette-core-90ae17c0d0f626763f456f061c472a66ec06eef1.tar.bz2 | |
Merge pull request #385 from af83/6203-journeypatternscollection-show--use-route-WayCosts-in-c
JourneyPatternsCollection#show use route way costs as default cost. Refs #6203
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/route_way_cost_unit_converter.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/route_way_cost_unit_converter.rb b/lib/route_way_cost_unit_converter.rb new file mode 100644 index 000000000..45edbf538 --- /dev/null +++ b/lib/route_way_cost_unit_converter.rb @@ -0,0 +1,25 @@ +class RouteWayCostUnitConverter + def self.convert(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 + end + + private + + # Round to 2 decimal places to appease JavaScript validation + def self.meters_to_kilometers(num) + return 0 unless num + + (num / 1000.0).to_i + end + + def self.seconds_to_minutes(num) + return 0 unless num + + num / 60 + end +end |
