Class: PomodoroTimer::RunningThread

Inherits:
Object
  • Object
show all
Defined in:
lib/pomodoro_timer/running_thread.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(will_work = false) ⇒ RunningThread

Returns a new instance of RunningThread.



5
6
7
8
9
10
11
12
# File 'lib/pomodoro_timer/running_thread.rb', line 5

def initialize(will_work=false)
  @will_work = will_work
  @cycle = Cycle::STOPPED

  @thread = Thread.new do
    run
  end
end

Instance Attribute Details

#cycleObject (readonly)

Returns the value of attribute cycle.



3
4
5
# File 'lib/pomodoro_timer/running_thread.rb', line 3

def cycle
  @cycle
end

Instance Method Details

#killObject



27
28
29
30
# File 'lib/pomodoro_timer/running_thread.rb', line 27

def kill
  @cycle = Cycle::STOPPED
  @thread.kill
end

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pomodoro_timer/running_thread.rb', line 14

def run
  if @will_work
    @cycle = Cycle.work
    @cycle.start
  end

  @cycle = Cycle.break
  @cycle.start

  puts "Pomodoro finished!(#{format(Time.now)})"
  @cycle = Cycle::STOPPED
end