Class: Stairs::Util::CLI::Collector

Inherits:
Object
  • Object
show all
Defined in:
lib/stairs/util/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(prompt, options = {}, &block) ⇒ Collector

Returns a new instance of Collector.



17
18
19
20
21
# File 'lib/stairs/util/cli.rb', line 17

def initialize(prompt, options = {}, &block)
  @prompt = prompt
  @options = options.reverse_merge required: true
  @validator = block
end

Instance Method Details

#runObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/stairs/util/cli.rb', line 23

def run
  times = 0
  value = nil

  until valid?(value, times)
    value = CLI.get(prompt.blue)
    times += 1
  end

  value
end