Class: AskService

Inherits:
Object
  • Object
show all
Defined in:
lib/ask_service.rb

Class Method Summary collapse

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


2
3
4
# File 'lib/ask_service.rb', line 2

def self.available?
  STDIN.tty?
end

.choose(label, options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/ask_service.rb', line 6

def self.choose(label, options)
  result = options.first
  printf "#{label} (#{options.join(", ")}) [#{options.first}]: "
  input = STDIN.gets.chomp
  result = input unless input.empty?
  unless options.include?(result)
    puts "That wasn't one of the available options.".colorize(:red) + " Please try again."
    result = choose(label, options)
  end
  result
end