class Command::Batch

Public Class Methods

new(statements) click to toggle source
# File lib/karel/command/batch.rb, line 5
def initialize(statements)
  @statements = statements
end

Public Instance Methods

execute(compass, location, tokens) click to toggle source
# File lib/karel/command/batch.rb, line 9
def execute(compass, location, tokens)
  operations_count = 0
  response = Response.new(
    compass: compass, location: location, tokens: tokens
  )
  @statements.each do |statement|
    response = statement.execute(
      response.compass, response.location, response.tokens
    )
    operations_count += response.operations_count
  end

  Response.new(
    compass: response.compass,
    location: response.location,
    operations_count: operations_count,
    tokens: response.tokens
  )
end