class Ruby::Pomodoro::Worker

Singleton for work with tasks in application

Attributes

current_task[R]
pomodoro_size[RW]
progressbar[RW]
time_interval[RW]

Private Instance Methods

notify() click to toggle source
# File lib/ruby/pomodoro/worker.rb, line 49
def notify
  notify_observers(aasm.current_event)
end
run_task(task) click to toggle source

@param [Ruby::Pomodoro::Task] task @return [TrueClass]

# File lib/ruby/pomodoro/worker.rb, line 55
def run_task(task)
  raise Error, "Setup pomodoro_size" if pomodoro_size.nil?

  @current_task = task
  @do = Thread.new do
    progress = progressbar || Ruby::Pomodoro::Progressbar.new(seconds: pomodoro_size)
    progress.start(task.name)
    count = 0
    loop do
      seconds = time_interval || 1
      sleep seconds
      unless paused?
        task.track(seconds)
        count += seconds
        progress.increment
        finish if count >= pomodoro_size.to_i && working?
      end
    end
  end
  true
end