Class: Nmap::Command::Time Private

Inherits:
CommandMapper::Types::Str
  • Object
show all
Defined in:
lib/nmap/command.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Represents a unit of time.

Constant Summary collapse

REGEXP =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Regular expression for validating a unit of time.

/\A\d+(?:h|m|s|ms)?\z/

Instance Method Summary collapse

Instance Method Details

#validate(value) ⇒ true, (false, String)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Validates a time value.

Parameters:

  • value (String, Integer)

    The time value to validate.

Returns:

  • (true, (false, String))

    Returns true if the value is considered valid, or false and a validation message if the value is not valid.



457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
# File 'lib/nmap/command.rb', line 457

def validate(value)
  case value
  when Integer then true
  else
    valid, message = super(value)

    unless valid
      return [valid, message]
    end

    value = value.to_s

    unless value =~ REGEXP
      return [false, "must be a number and end with 'ms', 's', 'm', or 'h'"]
    end

    return true
  end
end