Module: TimePresenter

Included in:
Bike, Splits, Swim
Defined in:
lib/time_presenter.rb

Instance Method Summary collapse

Instance Method Details

#present_hours_as_string(time) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/time_presenter.rb', line 2

def present_hours_as_string(time)
  hours = time.floor
  fraction = time - hours
  minutes = (60.0 * fraction)
  minutes_string = minutes.floor.to_s
  minutes_string = "0#{minutes_string}" if minutes < 10.0 && hours > 0.0
  fraction = minutes - minutes.floor
  seconds = (60.0 * fraction)
  seconds_string = seconds.round.to_s
  seconds_string = "0#{seconds_string}" if seconds < 10.0
  if hours > 0.0
    "#{hours}:#{minutes_string}:#{seconds_string}"
  elsif minutes > 0.0
    "#{minutes_string}:#{seconds_string}"
  else
    "0:#{seconds_string}"
  end
end

#present_seconds_as_string(time_in_seconds) ⇒ Object



20
21
22
23
# File 'lib/time_presenter.rb', line 20

def present_seconds_as_string(time_in_seconds)
  hours = time_in_seconds.to_f / 3600.0
  present_hours_as_string hours
end