Sha256: 53e926315bcc39479bb159dfbeedb8fa1720858cd439c7223c5c24d4e89b24f3

Contents?: true

Size: 629 Bytes

Versions: 3

Compression:

Stored size: 629 Bytes

Contents

class SlimKeyfy::Console::IOAction
  def self.yes_or_no?(msg)
    puts "#{msg} (y|n)"
    arg = STDIN.gets.chomp
    if arg =~ /[yY](es)?/
      true
    elsif arg =~ /[nN]o?/
      false
    else
      puts "Provide either (y)es or (n)o!"
      self.yes_or_no?(msg)
    end
  end
  def self.choose(msg)
    puts "#{msg} (y|n) (x for tagging | (a)bort)"
    arg = STDIN.gets.chomp
    if arg =~ /[yY](es)?/
      "y"
    elsif arg =~ /[nN]o?/
      "n"
    elsif arg =~ /x/
      "x"
    elsif arg =~ /a/
      "a"
    else
      puts "Either (y)es, (n)o, (x) for tagging or (a) to abort"
      self.choose(msg)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
slimkeyfy-0.1.0 lib/slimkeyfy/console/io_action.rb
slimkeyfy-0.0.4 lib/slimkeyfy/console/io_action.rb
slimkeyfy-0.0.3 lib/slimkeyfy/console/io_action.rb