Class: HighlineWrapper::Question

Inherits:
Object
  • Object
show all
Defined in:
lib/highline_wrapper/question.rb

Class Method Summary collapse

Class Method Details

.ask_highline(prompt, secret: false) ⇒ Object



6
7
8
9
10
# File 'lib/highline_wrapper/question.rb', line 6

def ask_highline(prompt, secret: false)
  highline.ask(prompt) do |conf|
    conf.echo = '*' if secret
  end
end

.format_options(prompt, choices) ⇒ Object



12
13
14
15
16
# File 'lib/highline_wrapper/question.rb', line 12

def format_options(prompt, choices)
  choices_as_string_options = ''.dup
  choices.each_with_index { |choice, index| choices_as_string_options << "#{index + 1}. #{choice}\n" }
  "#{prompt}\n#{choices_as_string_options.strip}"
end

.format_selection(choices, index, with_index) ⇒ Object



18
19
20
21
22
# File 'lib/highline_wrapper/question.rb', line 18

def format_selection(choices, index, with_index)
  response = { value: choices[index] }
  response[:index] = index if with_index
  response
end

.recurse(prompt, choices, options) ⇒ Object



24
25
26
27
# File 'lib/highline_wrapper/question.rb', line 24

def recurse(prompt, choices, options)
  puts "--- This question is required ---\n\n"
  choices.nil? ? ask(prompt, options) : ask(prompt, choices, options)
end

.return_empty_defaults(options) ⇒ Object



29
30
31
32
# File 'lib/highline_wrapper/question.rb', line 29

def return_empty_defaults(options)
  puts "--- Default selected: EMPTY ---\n\n" if options[:indicate_default_message]
  options[:defaults] || options[:default]
end