Class: Pomodoro::Commands::Postpone

Inherits:
Command
  • Object
show all
Defined in:
lib/pomodoro/commands/postpone.rb

Overview

1/5/2018: specs complete, help complete.

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from Pomodoro::Commands::Command

Instance Method Details

#runObject


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pomodoro/commands/postpone.rb', line 9

def run
  ensure_today

  if with_active_task(self.config) do |active_task|
        print "#{t(:prompt_why)} "
        reason = $stdin.readline.chomp
        print "#{t(:prompt_when)} "
        review_at = $stdin.readline.chomp

        if review_at.empty?
          review_date = active_task.postpone!(reason)
        else
          review_date = Date.strptime(review_at, '%d/%m')
          review_date = active_task.postpone!(reason, review_date)
        end

        puts t(:success, task: Pomodoro::Tools.unsentence(active_task.body), date: review_date.strftime('%-d/%-m'))
     end
  else
    abort t(:no_task_in_progress)
  end
end