class Ruby::Pomodoro::Cmd::ChooseTask

Select task and start worker

Public Instance Methods

call() click to toggle source

@param [Ruby::Pomodoro::Worker] worker

# File lib/ruby/pomodoro/cmd/choose_task.rb, line 7
def call
  worker.pause if worker.working?
  print
  task = Ruby::Pomodoro::Tasks::Resource.find(select_task(worker.current_task))
  Main.new.call
  if task
    worker.stop
    worker.start(task)
  else
    worker.resume if worker.paused?
  end
  :ok
end

Private Instance Methods

select_task(current_task) click to toggle source
# File lib/ruby/pomodoro/cmd/choose_task.rb, line 23
def select_task(current_task)
  options = Ruby::Pomodoro::Tasks::Resource.all.map do |task|
    disable = task == current_task ? "(The task in progress)" : nil
    { value: task.id, name: task.name, disabled: disable }
  end
  prompt.select("Select task", [*options, { name: "exit", value: 0 }])
end