Module: Ruby::Pomodoro::CommandController

Defined in:
lib/ruby/pomodoro/command_controller.rb

Class Method Summary collapse

Class Method Details

.call(event) ⇒ Object Also known as: keypress



5
6
7
8
9
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
35
36
37
# File 'lib/ruby/pomodoro/command_controller.rb', line 5

def call(event)
  signal =
    case event.value
    when 'q', 'й'
      Cmd::Quit.new.call(Pomodoro.editor)
    when 'c', 'с'
      Cmd::ChooseTask.new.call
    when 'e', 'у'
      Cmd::EditList.new.call(Pomodoro.editor)
    when 'p', 'з'
      Cmd::Pause.new.call
    when 's', 'ы'
      Cmd::Stop.new.call
    when 'R', 'К'
      Worker.instance.then do |worker|
        task = worker.current_task
        worker.start(task) if task
        Cmd::Main.new.call
      end
    when /[1-9]/
      Worker.instance.then do |worker|
        task = Ruby::Pomodoro::Tasks::Resource.find(event.value.to_i)
        return if task.nil? || task.id == worker.current_task&.id

        Cmd::Main.new.call
        worker.stop
        worker.start(task)
      end
    else
      Cmd::Main.new.call
    end
  abort if signal == :quit
end