Class: Danger::Interviewer

Inherits:
Object
  • Object
show all
Defined in:
lib/danger/commands/init_helpers/interviewer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cork_board) ⇒ Interviewer

Returns a new instance of Interviewer.



7
8
9
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 7

def initialize(cork_board)
  @ui = cork_board
end

Instance Attribute Details

#no_delayObject

Returns the value of attribute no_delay.



5
6
7
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 5

def no_delay
  @no_delay
end

#no_waitingObject

Returns the value of attribute no_waiting.



5
6
7
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 5

def no_waiting
  @no_waiting
end

#uiObject

Returns the value of attribute ui.



5
6
7
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 5

def ui
  @ui
end

Instance Method Details

#ask_with_answers(question, possible_answers) ⇒ Object



57
58
59
60
61
62
63
64
65
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
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 57

def ask_with_answers(question, possible_answers)
  ui.print "\n#{question}? ["

  print_info = proc do
    possible_answers.each_with_index do |answer, i|
      the_answer = i.zero? ? answer.underlined : answer
      ui.print " #{the_answer}"
      ui.print(" /") if i != possible_answers.length - 1
    end
    ui.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
      ui.puts "Using: #{answer.yellow}"
    end

    break if possible_answers.map(&:downcase).include? answer

    ui.print "\nPossible answers are ["
    print_info.call
  end

  answer
end

#green_bangObject



19
20
21
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 19

def green_bang
  "! ".green
end

#header(title) ⇒ Object



31
32
33
34
35
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 31

def header(title)
  say title.yellow
  say ""
  pause 0.6
end


37
38
39
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 37

def link(url)
  say " -> #{url.underlined}\n"
end

#pause(time) ⇒ Object



41
42
43
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 41

def pause(time)
  sleep(time) unless @no_waiting
end

#red_bangObject



23
24
25
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 23

def red_bang
  "! ".red
end

#run_command(command, output_command = nil) ⇒ Object



51
52
53
54
55
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 51

def run_command(command, output_command = nil)
  output_command ||= command
  ui.puts "  #{output_command.magenta}"
  system command
end

#say(output) ⇒ Object



27
28
29
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 27

def say(output)
  ui.puts output
end

#show_promptObject



11
12
13
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 11

def show_prompt
  ui.print "> ".bold.green
end

#wait_for_returnObject



45
46
47
48
49
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 45

def wait_for_return
  STDOUT.flush
  STDIN.gets unless @no_delay
  ui.puts
end

#yellow_bangObject



15
16
17
# File 'lib/danger/commands/init_helpers/interviewer.rb', line 15

def yellow_bang
  "! ".yellow
end