Class: Cotta::CommandInterface
- Inherits:
-
Object
- Object
- Cotta::CommandInterface
- Defined in:
- lib/cotta/impl/command_interface.rb
Overview
A command line interface tha can be stubbed out by InMemorySystem
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.
5 6 7 |
# File 'lib/cotta/impl/command_interface.rb', line 5 def initialize(io = SystemIo.new) @io = io end |
Instance Method Details
#gets ⇒ Object
31 32 33 |
# File 'lib/cotta/impl/command_interface.rb', line 31 def gets @io.gets end |
#prompt(question) ⇒ Object
13 14 15 16 |
# File 'lib/cotta/impl/command_interface.rb', line 13 def prompt(question) puts(question) gets end |
#prompt_for_choice(question, candidates) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/cotta/impl/command_interface.rb', line 18 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
9 10 11 |
# File 'lib/cotta/impl/command_interface.rb', line 9 def puts(content) @io.puts(content) end |