aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLuc Donnet2018-04-10 11:04:44 +0200
committerGitHub2018-04-10 11:04:44 +0200
commitf627d82ce180fb0e487195485402d3278c03d2ef (patch)
tree49f1c325f5cc2a1d91a2e3927d29eea692f44049 /lib
parent8ebad7aab4e8f46e3af64e86e7526c3b5f018cf7 (diff)
parentbfb194c5294c583dbf0bc0bef78b67d64a3a4f4c (diff)
downloadchouette-core-f627d82ce180fb0e487195485402d3278c03d2ef.tar.bz2
Merge pull request #450 from af83/6404-way-costs--snap-distance-and-time-to-1-when-between-0-a
6404: RouteWayCostUnitConverter: Snap values between 0–1 to 1
Diffstat (limited to 'lib')
-rw-r--r--lib/route_way_cost_unit_converter.rb14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/route_way_cost_unit_converter.rb b/lib/route_way_cost_unit_converter.rb
index 45edbf538..52515e52c 100644
--- a/lib/route_way_cost_unit_converter.rb
+++ b/lib/route_way_cost_unit_converter.rb
@@ -8,18 +8,24 @@ class RouteWayCostUnitConverter
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
+ snap_to_one(num / 1000.0).to_i
end
def self.seconds_to_minutes(num)
return 0 unless num
- num / 60
+ snap_to_one(num / 60.0).to_i
+ end
+
+ private
+
+ def self.snap_to_one(decimal)
+ return 1 if decimal > 0 && decimal <= 1
+
+ decimal
end
end