class HighlineWrapper::CheckboxQuestion

Public Class Methods

ask(prompt, choices, options) click to toggle source
# File lib/highline_wrapper/checkbox_question.rb, line 8
def ask(prompt, choices, options)
  indices = ask_highline(format_options(prompt, choices))

  return format_multiple_selections(choices, indices, options[:with_indexes]) unless indices.empty?
  return recurse(prompt, choices, options) if options[:required]
  return return_empty_defaults(options) if options[:defaults].empty?

  return_defaults(choices, options)
end

Private Class Methods

ask_highline(prompt) click to toggle source
Calls superclass method
# File lib/highline_wrapper/checkbox_question.rb, line 18
        def ask_highline(prompt)
  indices = []
  super(prompt).to_s.split(',').each { |i| indices << i.strip.to_i - 1 }
  indices
end
format_multiple_selections(choices, indices, with_indexes) click to toggle source
# File lib/highline_wrapper/checkbox_question.rb, line 35
        def format_multiple_selections(choices, indices, with_indexes)
  selected = []
  indices.each { |index| selected << format_selection(choices, index, with_indexes) }
  selected
end
print_default_message(options, choices) click to toggle source
return_defaults(choices, options) click to toggle source
# File lib/highline_wrapper/checkbox_question.rb, line 24
        def return_defaults(choices, options)
  options[:default_indexes] = options[:defaults].map { |d| choices.index(d) }
  print_default_message(options, choices) if options[:indicate_default_message]
  format_multiple_selections(choices, options[:default_indexes], options[:with_indexes])
end