module Setuper
Constants
- VERSION
Public Instance Methods
ask(question)
click to toggle source
# File lib/setuper.rb, line 14 def ask(question) io.puts question io.gets.strip end
choose(*options, question: "Please choose:")
click to toggle source
choose
# File lib/setuper.rb, line 28 def choose(*options, question: "Please choose:") option_map = options .map(&:to_s) .map .with_index { |x, i| [i + 1, x] } .to_h begin io.puts question option_map.each do |key, option| io.puts " Type #{key} for \"#{option}\"" end input = io.gets.chomp.to_i end until option_map.keys.include?(input) option_map[input] end
Also aliased as: pick
io()
click to toggle source
# File lib/setuper.rb, line 52 def io @io ||= Kernel end
io=(io)
click to toggle source
# File lib/setuper.rb, line 48 def io=(io) @io = io end
list(question)
click to toggle source
# File lib/setuper.rb, line 19 def list(question) io.puts question + " (Comma separated)" texts = io.gets.split(',').map(&:strip) io.puts "Okay, got #{texts.count} items." texts end
Also aliased as: ask_for_list
yn?(question)
click to toggle source
# File lib/setuper.rb, line 6 def yn?(question) begin io.puts question + " [y/n]" input = io.gets.chomp end until %w(y n).include?(input) input == 'y' end