Class: BuildMaster::CommandInterface
- Inherits:
-
Object
- Object
- BuildMaster::CommandInterface
- Defined in:
- lib/buildmaster/cotta/command_interface.rb
Instance Method Summary collapse
- #gets ⇒ Object
-
#initialize(io = SystemIo.new) ⇒ CommandInterface
constructor
A new instance of CommandInterface.
- #prompt(question) ⇒ Object
- #prompt_for_choice(question, candidates) ⇒ Object
- #puts(content) ⇒ Object
Constructor Details
#initialize(io = SystemIo.new) ⇒ CommandInterface
Returns a new instance of CommandInterface.
3 4 5 |
# File 'lib/buildmaster/cotta/command_interface.rb', line 3 def initialize(io = SystemIo.new) @io = io end |
Instance Method Details
#gets ⇒ Object
29 30 31 |
# File 'lib/buildmaster/cotta/command_interface.rb', line 29 def gets @io.gets end |
#prompt(question) ⇒ Object
11 12 13 14 |
# File 'lib/buildmaster/cotta/command_interface.rb', line 11 def prompt(question) puts(question) gets end |
#prompt_for_choice(question, candidates) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/buildmaster/cotta/command_interface.rb', line 16 def prompt_for_choice(question, candidates) puts(question) 0.upto(candidates.size - 1) do |index| puts "[#{index + 1}] #{candidates[index]}" end answer = gets.to_i seletion = nil if answer > 0 && answer <= candidates.size selection = candidates[answer - 1] end return selection end |
#puts(content) ⇒ Object
7 8 9 |
# File 'lib/buildmaster/cotta/command_interface.rb', line 7 def puts(content) @io.puts(content) end |