Class: CycleRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/core/cycle_runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(cycles, pomodoro_time, pause_time, break_time) ⇒ CycleRunner

Returns a new instance of CycleRunner.



3
4
5
6
7
8
# File 'lib/core/cycle_runner.rb', line 3

def initialize cycles, pomodoro_time, pause_time, break_time
  @timer_pomodoro = Timer.new pomodoro_time
  @timer_pause = Timer.new pause_time
  @timer_break = Timer.new break_time
  @cycles = cycles
end

Instance Method Details

#runObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/core/cycle_runner.rb', line 10

def run
  @thread = Thread.new do
    begin
      @cycles.times do |i|
        Window.instance.pop_up
        @timer_pomodoro.run
        
        if i + 1 != @cycles
          Window.instance.panel.button_start.label = "Time for a litle pause..."
          Window.instance.pop_up
          @timer_pause.run
        end
      end
      Window.instance.panel.button_start.label = "Now it's time to rest..."
      Window.instance.pop_up
      @timer_break.run
    rescue => e
      puts e
      Thread.stop
    end
    Window.instance.pop_up
    Window.instance.panel.button_start.enable
  end
  
end

#stopObject



36
37
38
39
40
41
# File 'lib/core/cycle_runner.rb', line 36

def stop
  @thread.kill
  Window.instance.panel.button_start.enable
  Window.instance.panel.progress_bar.text = "Canceled"
  Window.instance.panel.progress_bar.fraction = 0
end