class Nmap::Command::Port

Represents a port number.

@api private

Constants

PORT_NUMBER_REGEXP

Regular expression that validates a port number.

PORT_REGEXP

Regular expression that validates either a port number or service name.

REGEXP

Regular expression that validates either a port number or service name.

SERVICE_NAME_REGEXP

Regular expression that validates a service name.

Public Class Methods

new() click to toggle source

Initializes the port type.

Calls superclass method
# File lib/nmap/command.rb, line 210
def initialize
  super(range: 1..65535)
end

Public Instance Methods

format(value) click to toggle source

Formats the given value.

@param [Integer, String] value

The port number value to format.

@return [String]

The formatted port number.
Calls superclass method
# File lib/nmap/command.rb, line 246
def format(value)
  case value
  when String
    value
  else
    super(value)
  end
end
validate(value) click to toggle source

Validates the given port number value.

@param [Object] value

The value to validate.

@return [true, (false, String)]

Returns true if the value is valid, or `false` and a validation error
message if the value is not compatible.
Calls superclass method
# File lib/nmap/command.rb, line 224
def validate(value)
  case value
  when String
    if value =~ REGEXP
      return true
    else
      return [false, "must be a valid port number or service name (#{value.inspect})"]
    end
  else
    super(value)
  end
end