Class: Toy::Controller
- Inherits:
-
Object
- Object
- Toy::Controller
- Defined in:
- lib/toy/controller.rb
Constant Summary collapse
- COMMANDS =
%w[STOP HELP PLACE MOVE LEFT RIGHT REPORT]
Instance Attribute Summary collapse
-
#robot ⇒ Object
readonly
Returns the value of attribute robot.
Instance Method Summary collapse
-
#initialize ⇒ Controller
constructor
A new instance of Controller.
- #start ⇒ Object
Constructor Details
#initialize ⇒ Controller
Returns a new instance of Controller.
9 10 11 |
# File 'lib/toy/controller.rb', line 9 def initialize @robot = Toy::Robot.new end |
Instance Attribute Details
#robot ⇒ Object (readonly)
Returns the value of attribute robot.
7 8 9 |
# File 'lib/toy/controller.rb', line 7 def robot @robot end |
Instance Method Details
#start ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/toy/controller.rb', line 13 def start while command = gets unless Toy::Controller::COMMANDS.include?(command.gsub(/^[A-Z]+/).first) puts 'Invalid command! Type HELP for list of available commands.' and next end case command when /STOP/ break else output = execute(command.strip) puts output if output end end end |