Class: Danger::Interviewer
- Inherits:
-
Object
- Object
- Danger::Interviewer
- Defined in:
- lib/danger/commands/init_helpers/interviewer.rb
Instance Attribute Summary collapse
-
#no_delay ⇒ Object
Returns the value of attribute no_delay.
-
#no_waiting ⇒ Object
Returns the value of attribute no_waiting.
Instance Method Summary collapse
- #ask(question) ⇒ Object
- #ask_with_answers(question, possible_answers) ⇒ Object
- #green_bang ⇒ Object
- #header(title) ⇒ Object
- #link(url) ⇒ Object
- #pause(time) ⇒ Object
- #red_bang ⇒ Object
- #run_command(command, output_command = nil) ⇒ Object
- #say(output) ⇒ Object
- #show_prompt ⇒ Object
- #wait_for_return ⇒ Object
- #yellow_bang ⇒ Object
Instance Attribute Details
#no_delay ⇒ Object
Returns the value of attribute no_delay.
3 4 5 |
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 3 def no_delay @no_delay end |
#no_waiting ⇒ Object
Returns the value of attribute no_waiting.
3 4 5 |
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 3 def no_waiting @no_waiting end |
Instance Method Details
#ask(question) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 51 def ask(question) answer = "" loop do puts "\n#{question}?" show_prompt answer = STDIN.gets.chomp break if answer.empty? print "\nYou need to provide an answer." end answer end |
#ask_with_answers(question, possible_answers) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 66 def ask_with_answers(question, possible_answers) print "\n#{question}? [" print_info = proc do possible_answers.each_with_index do |answer, i| the_answer = (i == 0) ? answer.underline : answer print " " + the_answer print(" /") if i != possible_answers.length - 1 end print " ]\n" end print_info.call answer = "" loop do show_prompt answer = @no_waiting ? possible_answers[0].downcase : STDIN.gets.downcase.chomp answer = "yes" if answer == "y" answer = "no" if answer == "n" # default to first answer if answer == "" answer = possible_answers[0].downcase puts "Using: " + answer.yellow end break if possible_answers.map(&:downcase).include? answer print "\nPossible answers are [" print_info.call end answer end |
#green_bang ⇒ Object
13 14 15 |
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 13 def green_bang "! ".green end |
#header(title) ⇒ Object
25 26 27 28 29 |
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 25 def header(title) say title.yellow say '' pause 0.6 end |
#link(url) ⇒ Object
31 32 33 |
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 31 def link(url) say " -> " + url.underline + "\n" end |
#pause(time) ⇒ Object
35 36 37 |
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 35 def pause(time) sleep(time) unless @no_waiting end |
#red_bang ⇒ Object
17 18 19 |
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 17 def red_bang "! ".red end |
#run_command(command, output_command = nil) ⇒ Object
45 46 47 48 49 |
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 45 def run_command(command, output_command = nil) output_command ||= command puts " " + output_command.magenta system command end |
#say(output) ⇒ Object
21 22 23 |
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 21 def say(output) puts output end |
#show_prompt ⇒ Object
5 6 7 |
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 5 def show_prompt print "> ".bold.green end |
#wait_for_return ⇒ Object
39 40 41 42 43 |
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 39 def wait_for_return STDOUT.flush STDIN.gets unless @no_delay puts "" end |
#yellow_bang ⇒ Object
9 10 11 |
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 9 def yellow_bang "! ".yellow end |