lib/robot/command_proxy.rb in robot_rea-0.1.5 vs lib/robot/command_proxy.rb in robot_rea-0.1.6
- old
+ new
@@ -1,12 +1,13 @@
-# This class implements the proxy design pattern. It sits between the client and the commands,
-# and only invokes the command if it passes validation.
+# frozen_string_literal: true
+
module Robot
+ # This class implements the proxy design pattern. It sits between the client and the commands,
+ # and only invokes the command if it passes validation.
class CommandProxy
+ attr_reader :command_string, :position
- attr_reader :command_string, :position, :min_point, :max_point
-
def initialize(command_string:, position: nil)
@command_string = command_string
@position = position
end
@@ -31,9 +32,10 @@
Robot::Commands::Factory.build(command_string)
end
def would_fall?
return unless [Robot::Commands::Move, Robot::Commands::Place].include?(command_class)
+
new_position = execute
new_position.point > table.max_point || new_position.point < table.min_point
end
def table