Sha256: 0d24608bfe0f5974f47ff585adae3c5b52db760030338387d36c34e455a44f8b
Contents?: true
Size: 1.08 KB
Versions: 1
Compression:
Stored size: 1.08 KB
Contents
module Prompt def self.prompt(*args) print(*args) STDIN.gets.chomp end def self.bool(message) message = message + " (y/n): " input = prompt message input = input.strip return input.casecmp("y") == 0 || input.casecmp("yes") == 0 end def self.integer(min, max, message) input = prompt "> #{message}: " input = input.strip.to_i if input < min || input > max puts "! Specified index #{input} is outside allowed range #{min}-#{max}" return integer(min, max, message) else return input end end def self.index(options_array, message) selected_index = integer(0, options_array.size - 1, message) puts "selected_index: #{selected_index}" puts options_array.inspect return options_array[selected_index] end def self.option(options_hash, message) options_hash.each { |k,v| puts "[#{k}] #{v}" } input = prompt "> #{message}: " input = input.strip selected_option = options_hash[input] if selected_option.nil? puts "! Specified option '#{input}' is not available" return option(options_hash, message) else return selected_option end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
podmode-0.2.0 | lib/podmode/prompt.rb |