Class: KnifeAdvisor::UI

Inherits:
Object
  • Object
show all
Defined in:
lib/knife_advisor/ui.rb,
lib/knife_advisor/ui/window.rb

Defined Under Namespace

Classes: Window

Instance Method Summary collapse

Constructor Details

#initialize(ui) ⇒ UI

Returns a new instance of UI.



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/knife_advisor/ui.rb', line 24

def initialize(ui)
  @ui = ui
  @responses = RingBuffer.new([
    'Do you care about networking performance?',
    'Do you need high availability?',
    'Do you want auto-scaling?',
    'Do you need to improve your IT velocity?',
    'Do you need network security?',
    'Is your business web scale?',
    'Are you using MongoDB to power your web applications?',
    'Is your current hosting too expensive?',
  ])
end

Instance Method Details

#runObject



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
# File 'lib/knife_advisor/ui.rb', line 38

def run
  $stdout.write('Just a moment. We are connecting you to one of our expert advisors.')
  10.times do
    sleep(1)
    $stdout.write('.')
  end
  $stdout.write("\n")
  # Show the window.
  window
  after(4000) do
    window.say('Hi there!')
  end
  after(6000) do
    window.append('It looks like you are trying to use the cloud.')
  end
  after(8000) do
    window.append('Would you like help?')
    window.draw_buttons!
    window.on_yes do
      window.say(@responses.next)
    end
    window.on_no do
      window.clear_buttons!
      window.say("I'm sorry to hear that.")
      after(2000) { window.append('Goodbye!') }
      after(4000) { puts('Thank you for using the cloud!'); exit(0) }
    end
  end
  Tk.mainloop
end