Class: Robot::CommandProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/robot/command_proxy.rb

Overview

This class implements the proxy design pattern. It sits between the client and the commands, and only invokes the command if it passes validation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command_string:, position: nil) ⇒ CommandProxy

Returns a new instance of CommandProxy.



9
10
11
12
# File 'lib/robot/command_proxy.rb', line 9

def initialize(command_string:, position: nil)
  @command_string = command_string
  @position = position
end

Instance Attribute Details

#command_stringObject (readonly)

Returns the value of attribute command_string.



7
8
9
# File 'lib/robot/command_proxy.rb', line 7

def command_string
  @command_string
end

#positionObject (readonly)

Returns the value of attribute position.



7
8
9
# File 'lib/robot/command_proxy.rb', line 7

def position
  @position
end

Instance Method Details

#callObject



14
15
16
17
18
19
# File 'lib/robot/command_proxy.rb', line 14

def call
  return if not_placed_yet? && !place_command?
  return position if would_fall?

  execute
end