Class: James::Inputs::Terminal

Inherits:
Base
  • Object
show all
Defined in:
lib/james/inputs/terminal.rb

Overview

Terminal input for silent purposes.

Instance Attribute Summary

Attributes inherited from Base

#controller

Instance Method Summary collapse

Methods inherited from Base

#heard, #initialize, #show_possibilities

Constructor Details

This class inherits a constructor from James::Inputs::Base

Instance Method Details

#get_commandObject

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

#listenObject

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