Module: Setuper

Extended by:
Setuper
Included in:
Setuper
Defined in:
lib/setuper.rb,
lib/setuper/version.rb

Constant Summary collapse

VERSION =
"0.2.0"

Instance Method Summary collapse

Instance Method Details

#ask(question) ⇒ Object



14
15
16
17
# File 'lib/setuper.rb', line 14

def ask(question)
  io.puts question
  io.gets.strip
end

#choose(*options, question: "Please choose:") ⇒ Object Also known as: pick

choose



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/setuper.rb', line 28

def choose(*options, question: "Please choose:")
  option_map = options
    .map(&:to_s)
    .map
    .with_index { |x, i| [i + 1, x] }
    .to_h

  begin
    io.puts question

    option_map.each do |key, option|
      io.puts "  Type #{key} for \"#{option}\""
    end
    input = io.gets.chomp.to_i
  end until option_map.keys.include?(input)

  option_map[input]
end

#ioObject



52
53
54
# File 'lib/setuper.rb', line 52

def io
  @io ||= Kernel
end

#io=(io) ⇒ Object



48
49
50
# File 'lib/setuper.rb', line 48

def io=(io)
  @io = io
end

#list(question) ⇒ Object Also known as: ask_for_list



19
20
21
22
23
24
# File 'lib/setuper.rb', line 19

def list(question)
  io.puts question + " (Comma separated)"
  texts = io.gets.split(',').map(&:strip)
  io.puts "Okay, got #{texts.count} items."
  texts
end

#yn?(question) ⇒ Boolean

Returns:

  • (Boolean)


6
7
8
9
10
11
12
# File 'lib/setuper.rb', line 6

def yn?(question)
  begin
    io.puts question + " [y/n]"
    input = io.gets.chomp
  end until %w(y n).include?(input)
  input == 'y'
end