class MatherService

Public Instance Methods

add(req, _) click to toggle source

add adds two numbers

# File src/svc/mather.rb, line 15
def add(req, _)
  # Validate input
  if req.First == 0
    msg = 'Could not add, `First` has not been provided'
    LOG.error msg
    raise GRPC::BadStatus.new(GRPC::Core::StatusCodes::INVALID_ARGUMENT, msg)
  end
  if req.Second == 0
    msg = 'Could not add, `Second` has not been provided'
    LOG.error msg
    raise GRPC::BadStatus.new(GRPC::Core::StatusCodes::INVALID_ARGUMENT, msg)
  end

  # Log progress
  LOG.info "Adding #{req.First} to #{req.Second}"

  # Return added numbers
  Mather::MathAddReply.new(Result: MatherLib.new.add(req.First, req.Second))
end
subtract(req, _) click to toggle source

subtract subtracts two numbers

# File src/svc/mather.rb, line 36
def subtract(req, _)
  # Validate input
  if req.First == 0
    msg = 'Could not subtract, `First` has not been provided'
    LOG.error msg
    raise GRPC::BadStatus.new(GRPC::Core::StatusCodes::INVALID_ARGUMENT, msg)
  end
  if req.Second == 0
    msg = 'Could not subtract, `Second` has not been provided'
    LOG.error msg
    raise GRPC::BadStatus.new(GRPC::Core::StatusCodes::INVALID_ARGUMENT, msg)
  end

  # Log progress
  LOG.info "Subtracting #{req.First} from #{req.Second}"

  # Return subtracted numbers
  Mather::MathSubtractReply.new(
    Result: MatherLib.new.subtract(req.First, req.Second)
  )
end