Module: Prompt

Defined in:
lib/podmode/prompt.rb

Class Method Summary collapse

Class Method Details

.bool(message) ⇒ Object



8
9
10
11
12
13
# File 'lib/podmode/prompt.rb', line 8

def self.bool(message)
	message = message + " (y/n): "
	input = prompt message
	input = input.strip
	return input.casecmp("y") == 0 || input.casecmp("yes") == 0
end

.index(options_array, message) ⇒ Object



26
27
28
29
30
31
# File 'lib/podmode/prompt.rb', line 26

def self.index(options_array, message)
	selected_index = integer(0, options_array.size - 1, message)
	puts "selected_index: #{selected_index}"
	puts options_array.inspect
	return options_array[selected_index]
end

.integer(min, max, message) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/podmode/prompt.rb', line 15

def self.integer(min, max, message)
	input = prompt "> #{message}: "
	input = input.strip.to_i
	if input < min || input > max
		puts "! Specified index #{input} is outside allowed range #{min}-#{max}"
		return integer(min, max, message)
	else
		return input
	end
end

.option(options_hash, message) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/podmode/prompt.rb', line 33

def self.option(options_hash, message)
	options_hash.each { |k,v| puts "[#{k}] #{v}" }
	input = prompt "> #{message}: "
	input = input.strip

	selected_option = options_hash[input]
	if selected_option.nil?
		puts "! Specified option '#{input}' is not available"
		return option(options_hash, message)
	else
		return selected_option
	end
end

.prompt(*args) ⇒ Object



3
4
5
6
# File 'lib/podmode/prompt.rb', line 3

def self.prompt(*args)
    print(*args)
    STDIN.gets.chomp
end