Class: SlimKeyfy::Console::IOAction

Inherits:
Object
  • Object
show all
Defined in:
lib/slimkeyfy/console/io_action.rb

Class Method Summary collapse

Class Method Details

.choose(msg) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/slimkeyfy/console/io_action.rb', line 14

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

.yes_or_no?(msg) ⇒ Boolean

Returns:

  • (Boolean)


2
3
4
5
6
7
8
9
10
11
12
13
# File 'lib/slimkeyfy/console/io_action.rb', line 2

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