Class: TomatoPaste::Cli

Inherits:
Object
  • Object
show all
Defined in:
lib/tomato_paste/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(input = $stdin, output = $stdout) ⇒ Cli

Returns a new instance of Cli.



11
12
13
14
15
# File 'lib/tomato_paste/cli.rb', line 11

def initialize(input = $stdin, output = $stdout)
  @input = input
  @output = output
  @vine = TomatoPaste::Vine.new
end

Instance Method Details

#ascii_bannerObject

Prints the colored “logo” of sorts “jgs” is the author of this awesome ascii tomato



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/tomato_paste/cli.rb', line 25

def ascii_banner
  banner = "               |  \n"
  banner += "   __\\W/__     ".green.bold + "|   _____                     _          ____           _       \n"
  banner += " .'.-'|'-.'.   ".red.bold + "|  |_   _|__  _ __ ___   __ _| |_ ___   |  _ \\ __ _ ___| |_ ___ \n"
  banner += "/           \\  ".red.bold + "|    | |/ _ \\| '_ ` _ \\ / _` | __/ _ \\  | |_) / _` / __| __/ _ \\\n"
  banner += "|           |  ".red.bold + "|    | | (_) | | | | | | (_| | || (_) | |  __/ (_| \\__ \\ ||  __/\n"
  banner += " \\         /   ".red.bold + "|    |_|\\___/|_| |_| |_|\\__,_|\\__\\___/  |_|   \\__,_|___/\\__\\___|\n"
  banner += "  '-.___.-'    ".red.bold + "|  \n"
  banner += "jgs".yellow.bold + "            |   \n"
  banner += "                                                           ...a Pomodoro timer\n"

  banner
end

#runObject



17
18
19
20
21
# File 'lib/tomato_paste/cli.rb', line 17

def run
  @output.print ascii_banner
  task_loop
  @output.print "\n\nBye!"
end

#task_loop(big_break_duration = 1200) ⇒ Object

20 minutes



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/tomato_paste/cli.rb', line 39

def task_loop(big_break_duration=1200) # 20 minutes
  begin
    @output.print "\n\n"
    @output.print "Task Description: "
    task_description = @input.gets.chomp

    @vine.add(TomatoPaste::Pomodoro.new(task_description))

    @output.puts
    emit_notification "Starting Pomodoro ##{@vine.pomodori.count}"

    @vine.current_pomodoro.work_timer.start

    TomatoPaste::Notification.play_audio_alert

    if @vine.big_break_time?
      emit_notification "It's time for a big break. Come back in 20 minutes."
      Timer.new(big_break_duration).start
    else
      emit_notification "Pomodoro ##{@vine.pomodori.count} complete. Break starts now!"
      @vine.current_pomodoro.break_timer.start
    end

    TomatoPaste::Notification.play_audio_alert

    emit_notification "Break done!"

    @output.print "\nDo another Pomodoro? (Y/N): "
  end while @input.gets.upcase.chomp != "N"
end