class HighlineWrapper::Question
Public Class Methods
ask_highline(prompt, secret: false)
click to toggle source
# File lib/highline_wrapper/question.rb, line 6 def ask_highline(prompt, secret: false) highline.ask(prompt) do |conf| conf.readline = true conf.echo = '*' if secret end end
format_options(prompt, choices)
click to toggle source
# File lib/highline_wrapper/question.rb, line 13 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)
click to toggle source
# File lib/highline_wrapper/question.rb, line 19 def format_selection(choices, index, with_index) response = { value: choices[index] } response[:index] = index if with_index response end
recurse(prompt, choices, options)
click to toggle source
# File lib/highline_wrapper/question.rb, line 25 def recurse(prompt, choices, options) puts '--- This question is required ---' choices.nil? ? ask(prompt, options) : ask(prompt, choices, options) end
return_empty_defaults(options)
click to toggle source
# File lib/highline_wrapper/question.rb, line 30 def return_empty_defaults(options) puts '--- Default selected: EMPTY ---' if options[:indicate_default_message] options[:defaults] || options[:default] end
Private Class Methods
highline()
click to toggle source
# File lib/highline_wrapper/question.rb, line 35 def highline @highline ||= HighLine.new end