Class: HiCathy::CLI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



14
15
16
17
18
# File 'lib/hi_cathy/cli.rb', line 14

def initialize
  @prompt = TTY::Prompt.new(interrupt: :exit)
  @pastel = Pastel.new
  @sms = HiCathy::SMS.new
end

Instance Attribute Details

#pastelObject (readonly)

Returns the value of attribute pastel.



12
13
14
# File 'lib/hi_cathy/cli.rb', line 12

def pastel
  @pastel
end

#promptObject (readonly)

Returns the value of attribute prompt.



12
13
14
# File 'lib/hi_cathy/cli.rb', line 12

def prompt
  @prompt
end

#smsObject (readonly)

Returns the value of attribute sms.



12
13
14
# File 'lib/hi_cathy/cli.rb', line 12

def sms
  @sms
end

Instance Method Details

#start!Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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
69
70
71
72
# File 'lib/hi_cathy/cli.rb', line 20

def start!
  hero! 'Hi, Cathy!'
  newline!
  newline!

  say! "First things first!"
  say! "We can't have you forgetting my most important defining characteristic again..."
  newline!
  prompt.ask('Which country am I from?', color: :cyan) do |q|
    q.validate /🇨🇦/, 'Nope! P.S. the answer is an emoji 😉'
  end
  spin_for!('Analyzing answer...') { wait! }
  say! 'You got it!'
  newline!

  wait!

  say! 'Next up: dinner plans!'
  say! 'Our playbook this time is to check out Kuma at a slighly less peak time, and fall back to Tycoon 😋'
  newline!

  excitment = prompt.slider('How excited are you for this??', max: 10, default: 8)

  say! 'Me too!' if excitment == 10
  newline!

  choice = prompt.select('Do any of these times work?') do |menu|
    menu.choice 'Wednesday the 13th at 6pm'
    menu.choice 'Saturday the 16th at noon'
    menu.choice 'Nope!', :none
  end

  unless choice == :none
    finish! choice
    return
  end

  newline!
  say! "Oh no! We'll have to wait until I'm back from Vietnam then."
  say! "Let's bruteforce a date that works..."

  day = Date.new(2019, 11, 27)
  until choice != :none
    choice = prompt.select("Do any of these times on #{format_day(day)} work?") do |menu|
      menu.choice "Noon" if day.saturday? || day.sunday?
      menu.choice "6pm"
      menu.choice 'Nope!', :none
    end
    day = day.next_day(1)
  end

  finish! "#{format_day(day)} at #{choice}"
end