Module: Timeless::Pomodoro

Defined in:
lib/timeless/pomodoro.rb

Constant Summary collapse

WORKING =
25
WORKING_LONG =
50
BREAK =
5
BREAK_LONG =
15
INTERVAL =
0.3

Class Method Summary collapse

Class Method Details

.run_pomodoro_timer(total_mins, notes = nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/timeless/pomodoro.rb', line 14

def self.run_pomodoro_timer total_mins, notes=nil
  start = Time.now
  total_secs = total_mins * 60
  s = 0
  _s = nil
  while true
    s = (Time.now - start).to_i
    r = total_secs - s
    printf("\r%i:%02i", r / 60, r % 60) if s != _s
    break if s >= total_secs
    _s = s
    sleep INTERVAL
  end
  print "\n"
 
  notifier = Notiffany.connect(title: "Pomodoro Complete!")
  notifier.notify("You clocked: #{total_mins} minute#{"s" if total_mins != 1}.\nYou deserve a break, now", image: :success)
  notifier.disconnect # some plugins like TMux and TerminalTitle rely on this

  [start, Time.now, notes]
end