Class: Minder::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/minder/timer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(seconds: DEFAULT_WORK_PERIOD) ⇒ Timer

Returns a new instance of Timer.



8
9
10
# File 'lib/minder/timer.rb', line 8

def initialize(seconds: DEFAULT_WORK_PERIOD)
  self.seconds = seconds
end

Instance Attribute Details

#secondsObject

Returns the value of attribute seconds.



5
6
7
# File 'lib/minder/timer.rb', line 5

def seconds
  @seconds
end

#start_timeObject

Returns the value of attribute start_time.



5
6
7
# File 'lib/minder/timer.rb', line 5

def start_time
  @start_time
end

Instance Method Details

#completed?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/minder/timer.rb', line 16

def completed?
  elapsed_time.to_i >= seconds
end

#elapsed_timeObject



20
21
22
23
24
# File 'lib/minder/timer.rb', line 20

def elapsed_time
  return 0 unless start_time

  (Time.now - start_time)
end

#start!Object



12
13
14
# File 'lib/minder/timer.rb', line 12

def start!
  self.start_time = Time.now
end

#to_sObject



26
27
28
29
# File 'lib/minder/timer.rb', line 26

def to_s
  "#{Minder.formatted_time(elapsed_time)} " \
    "(out of #{Minder.formatted_time(seconds)})"
end