Method: BetweenTheSheets::Ask.prompt

Defined in:
lib/between_the_sheets/ask.rb

.prompt(options = {}) ⇒ Object

Raises:



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(options = {})
  options = { to_int: false, match: nil }.merge(options)
  match = options[: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 options[:to_int]
    input.gsub(/\D/, "").to_i
  else
    input
  end
end