class BetweenTheSheets::Ask

Public Class Methods

print(output = "", options = {}) click to toggle source
prompt(options = {}) click to toggle source
# 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
puts(output = "", options = {}) click to toggle source
# File lib/between_the_sheets/ask.rb, line 8
def self.puts(output = "", options = {})
  $stdout.puts output
  prompt(options)
end