Added specs for ApplicationHelper.show_time

- refactor of code to use divmod and handle decimal number parameter
- return '0 h 0 min' if length blank
This commit is contained in:
charliequinn 2016-08-16 00:44:49 +01:00
parent 99992750bb
commit ef9ba3b981
2 changed files with 30 additions and 9 deletions

View file

@ -165,17 +165,16 @@ module ApplicationHelper
end
def show_time(length)
h = length / 60
min = length - h * 60
return '0 h 0 min' if length.blank?
if h != 0
if min != 0
"#{h} h #{min} min"
else
"#{h} h"
end
h, min = length.divmod(60)
if h == 0
"#{min.round} min"
elsif min == 0
"#{h} h"
else
"#{min} min"
"#{h} h #{min.round} min"
end
end