Class: ToyRobot::Simulator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table_size: {x: 5, y: 5}) ⇒ Simulator

Returns a new instance of Simulator.



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

def initialize(table_size: {x: 5, y: 5})
  @roboto = Roboto.new
  @table  = Table.new(table_size)
  inform_roboto_about_table
end

Instance Attribute Details

#robotoObject (readonly)

Returns the value of attribute roboto.



4
5
6
# File 'lib/toy_robot/simulator.rb', line 4

def roboto
  @roboto
end

#tableObject (readonly)

Returns the value of attribute table.



4
5
6
# File 'lib/toy_robot/simulator.rb', line 4

def table
  @table
end

Instance Method Details

#run(orders) ⇒ Object



12
13
14
15
16
17
# File 'lib/toy_robot/simulator.rb', line 12

def run(orders)
  orders.each do |order|
    understood = @roboto.understand_order(order)
    @roboto.execute_order(understood)
  end
end