Class: James::Inputs::Terminal
- Defined in:
- lib/james/inputs/terminal.rb
Overview
Terminal input for silent purposes.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#get_command ⇒ Object
Get the next command by the user.
-
#listen ⇒ Object
Start listening to commands by the user.
Methods inherited from Base
#heard, #initialize, #show_possibilities
Constructor Details
This class inherits a constructor from James::Inputs::Base
Instance Method Details
#get_command ⇒ Object
Get the next command by the user.
25 26 27 28 29 30 31 |
# File 'lib/james/inputs/terminal.rb', line 25 def get_command STDIN.gets.chop rescue IOError puts "Wait a second, please, Sir, I am busy." sleep 1 retry end |
#listen ⇒ Object
Start listening to commands by the user.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/james/inputs/terminal.rb', line 11 def listen sleep 2 loop do possibilities = controller.expects show_possibilities possibilities command = get_command puts "I heard '#{command}'." command = possibilities[command.to_i-1] unless command.to_i.zero? heard command if possibilities.include? command end end |