Module: Brewby::Timed

Included in:
Application, Steps::TempControl
Defined in:
lib/brewby/timed.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#end_timeObject (readonly)

Returns the value of attribute end_time.



3
4
5
# File 'lib/brewby/timed.rb', line 3

def end_time
  @end_time
end

#start_timeObject (readonly)

Returns the value of attribute start_time.



3
4
5
# File 'lib/brewby/timed.rb', line 3

def start_time
  @start_time
end

Instance Method Details

#countdown_for(seconds) ⇒ Object



35
36
37
38
39
# File 'lib/brewby/timed.rb', line 35

def countdown_for seconds
  sign = seconds > 0 ? "" : "+"

  sign + timer_for(seconds.abs)
end

#elapsedObject



25
26
27
# File 'lib/brewby/timed.rb', line 25

def elapsed
  started? ? (@end_time || Time.now) - @start_time :  0
end

#ended?Boolean



9
10
11
# File 'lib/brewby/timed.rb', line 9

def ended?
  !@end_time.nil?
end

#in_progress?Boolean



13
14
15
# File 'lib/brewby/timed.rb', line 13

def in_progress?
  started? && !ended?
end

#start_timerObject



17
18
19
# File 'lib/brewby/timed.rb', line 17

def start_timer
  @start_time = Time.now
end

#started?Boolean



5
6
7
# File 'lib/brewby/timed.rb', line 5

def started?
  !@start_time.nil?
end

#stop_timerObject



21
22
23
# File 'lib/brewby/timed.rb', line 21

def stop_timer
  @end_time = Time.now
end

#time_from_seconds(seconds) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/brewby/timed.rb', line 41

def time_from_seconds seconds
  hours = seconds / 3600
  seconds -= (hours * 3600)
  minutes = seconds / 60
  seconds -= minutes * 60

  [hours, minutes, seconds]
end

#timer_for(seconds) ⇒ Object



29
30
31
32
33
# File 'lib/brewby/timed.rb', line 29

def timer_for seconds
  time = seconds > 0 ? time_from_seconds(seconds) : [0, 0, 0]

  "%0.2d:%0.2d:%0.2d" % time
end