Module: Prompt
- Defined in:
- lib/podmode/prompt.rb
Class Method Summary collapse
- .bool(message) ⇒ Object
- .index(options_array, message) ⇒ Object
- .integer(min, max, message) ⇒ Object
- .option(options_hash, message) ⇒ Object
- .prompt(*args) ⇒ Object
Class Method Details
.bool(message) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/podmode/prompt.rb', line 8 def self.bool() = + " (y/n): " input = prompt input = input.strip return input.casecmp("y") == 0 || input.casecmp("yes") == 0 end |
.index(options_array, message) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/podmode/prompt.rb', line 26 def self.index(, ) selected_index = integer(0, .size - 1, ) puts "selected_index: #{selected_index}" puts .inspect return [selected_index] end |
.integer(min, max, message) ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/podmode/prompt.rb', line 15 def self.integer(min, max, ) input = prompt "> #{}: " input = input.strip.to_i if input < min || input > max puts "! Specified index #{input} is outside allowed range #{min}-#{max}" return integer(min, max, ) else return input end end |
.option(options_hash, message) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/podmode/prompt.rb', line 33 def self.option(, ) .each { |k,v| puts "[#{k}] #{v}" } input = prompt "> #{}: " input = input.strip selected_option = [input] if selected_option.nil? puts "! Specified option '#{input}' is not available" return option(, ) else return selected_option end end |
.prompt(*args) ⇒ Object
3 4 5 6 |
# File 'lib/podmode/prompt.rb', line 3 def self.prompt(*args) print(*args) STDIN.gets.chomp end |