class RubyRobot::Grpc::RobotService

Public Instance Methods

left(empty, _unused_call) click to toggle source
# File lib/ruby_robot/grpc/robot_service.rb, line 48
def left(empty, _unused_call)
  logger.info "#{__method__} called (robot.placed?==#{robot.placed?})"
  if robot.placed?
    robot.LEFT
    position_report
  else
    not_placed_error
  end
end
logger() click to toggle source
# File lib/ruby_robot/grpc/robot_service.rb, line 14
def logger
  @logger ||= proc {
    Logger.new(STDOUT)
  }.call
end
move(empty, _unused_call) click to toggle source
# File lib/ruby_robot/grpc/robot_service.rb, line 58
def move(empty, _unused_call)
  logger.info "#{__method__} called (robot.placed?==#{robot.placed?})"
  if robot.placed?
    robot.MOVE
    position_report
  else
    not_placed_error
  end
end
not_placed_error() click to toggle source
# File lib/ruby_robot/grpc/robot_service.rb, line 30
def not_placed_error
  ::RubyRobot::RubyRobotResponse.new(
    error: ::RubyRobot::RubyRobotError.new(error: 400, message: "Robot is not currently placed")
  )
end
place(robot_request, _unused_call) click to toggle source
# File lib/ruby_robot/grpc/robot_service.rb, line 68
def place(robot_request, _unused_call)
  input = { x: robot_request.x, y: robot_request.y, direction: robot_request.direction }
  logger.info "#{__method__} called with #{input.to_json}"

  robot.PLACE(robot_request.x, robot_request.y, robot_request.direction.to_s.downcase)
  position_report
end
position_report() click to toggle source
# File lib/ruby_robot/grpc/robot_service.rb, line 36
def position_report
  rr = robot.REPORT(false)

  ::RubyRobot::RubyRobotResponse.new(
    current_state: ::RubyRobot::RubyRobotRequest.new(
      x:         rr[:x],
      y:         rr[:y],
      direction: rr[:direction].to_s.upcase.to_sym
    )
  )
end
remove(empty, _unused_call) click to toggle source
# File lib/ruby_robot/grpc/robot_service.rb, line 76
def remove(empty, _unused_call)
  logger.info "#{__method__} called"
  @@robot = nil
  ::Google::Protobuf::Empty.new
end
report(empty, _unused_call) click to toggle source
# File lib/ruby_robot/grpc/robot_service.rb, line 82
def report(empty, _unused_call)
  logger.info "#{__method__} called (robot.placed?==#{robot.placed?})"
  if robot.placed?
    position_report
  else
    not_placed_error
  end
end
right(empty, _unused_call) click to toggle source
# File lib/ruby_robot/grpc/robot_service.rb, line 91
def right(empty, _unused_call)
  logger.info "#{__method__} called (robot.placed?==#{robot.placed?})"
  if robot.placed?
    robot.RIGHT
    position_report
  else
    not_placed_error
  end
end
robot() click to toggle source
# File lib/ruby_robot/grpc/robot_service.rb, line 20
def robot
  @@robot ||= proc {
    rr = ::RubyRobot::Shell.new
    def rr.placed?
      !@robot.nil?
    end
    rr
  }.call
end