Class: Producer::Core::Prompter

Inherits:
Object
  • Object
show all
Defined in:
lib/producer/core/prompter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, output) ⇒ Prompter

Returns a new instance of Prompter.



6
7
8
9
# File 'lib/producer/core/prompter.rb', line 6

def initialize input, output
  @input  = input
  @output = output
end

Instance Attribute Details

#inputObject (readonly)

Returns the value of attribute input.



4
5
6
# File 'lib/producer/core/prompter.rb', line 4

def input
  @input
end

#outputObject (readonly)

Returns the value of attribute output.



4
5
6
# File 'lib/producer/core/prompter.rb', line 4

def output
  @output
end

Instance Method Details

#prompt(question, choices) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/producer/core/prompter.rb', line 11

def prompt question, choices
  cs = choices.each_with_index.inject '' do |m, (c, i)|
    m + "#{i}: #{c.last}\n"
  end
  output.puts "#{question}\n#{cs}Choice:"
  choice = input.gets
  choices[choice.to_i].first
end