Class: BetweenTheSheets::Ask
- Inherits:
-
Object
- Object
- BetweenTheSheets::Ask
- Defined in:
- lib/between_the_sheets/ask.rb
Class Method Summary collapse
- .print(output = "", options = {}) ⇒ Object
- .prompt(options = {}) ⇒ Object
- .puts(output = "", options = {}) ⇒ Object
Class Method Details
.print(output = "", options = {}) ⇒ Object
3 4 5 6 |
# File 'lib/between_the_sheets/ask.rb', line 3 def self.print(output = "", = {}) $stdout.print output prompt() end |
.prompt(options = {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/between_the_sheets/ask.rb', line 13 def self.prompt( = {}) = { to_int: false, match: nil }.merge() match = [:match] input = gets.chomp.downcase raise ApplicationExit if input.match(/^q|quit|^e|exit/) raise ApplicationHelp if input.match(/^h|help/) if match && input.match(match).to_s.empty? input = loop do try = self.print("Invalid response. Choices are: " + match.to_s.gsub("?-mix:", "") + " ") break try if try.match(match) end end if [:to_int] input.gsub(/\D/, "").to_i else input end end |
.puts(output = "", options = {}) ⇒ Object
8 9 10 11 |
# File 'lib/between_the_sheets/ask.rb', line 8 def self.puts(output = "", = {}) $stdout.puts output prompt() end |