Class: ToyRobot::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/toy_robot/application.rb

Instance Method Summary collapse

Constructor Details

#initialize(argv = [], args = {}) ⇒ Application

Returns a new instance of Application.



6
7
8
9
10
# File 'lib/toy_robot/application.rb', line 6

def initialize(argv = [], args = {})
  @input = args[:input] || $stdin
  @parser = Command::Parser
  @controller = Factory.create(:controller)
end

Instance Method Details

#run(options = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/toy_robot/application.rb', line 12

def run(options = nil)
  loop do
    raw_input = input.gets
    break unless raw_input
    raw_input.chomp!
    command = parser.parse(raw_input)
    controller.send(command.msg, command.args) if command
  end
end