class Robotoy::Services::Place

Public Class Methods

new(robot:, table:, x:, y:, orient:) click to toggle source
# File lib/robotoy/services/place.rb, line 4
def initialize(robot:, table:, x:, y:, orient:)
  @robot = robot
  @table = table
  @x = x.to_i
  @y = y.to_i
  @orient = orient.downcase.to_sym
end

Public Instance Methods

perform() click to toggle source
# File lib/robotoy/services/place.rb, line 12
def perform
  validate_placement(@x, @y, @orient)
  @robot.x = @x
  @robot.y = @y
  @robot.orientation = @orient
end

Private Instance Methods

validate_placement(x, y, orientation) click to toggle source
# File lib/robotoy/services/place.rb, line 21
def validate_placement(x, y, orientation)
  @table.validate_next_position(x: x, y: y)
  @robot.validate_orientation(orientation: orientation)
end