Class: Masscan::Command::RotateTime Private

Inherits:
CommandMapper::Types::Str
  • Object
show all
Defined in:
lib/masscan/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 the type for the --rotate option.

Since:

  • 0.3.0

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 to validate the --rotate time value.

Since:

  • 0.3.0

/\A(?:\d+|hourly|\d+hours|\d+min)\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 --rotate time value.

Parameters:

  • value (Integer, String, #to_s)

    The time value to validate.

Returns:

  • (true, (false, String))

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

Since:

  • 0.3.0



392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
# File 'lib/masscan/command.rb', line 392

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

    unless valid
      return [valid, message]
    end

    string = value.to_s

    unless string =~ REGEXP
      return [false, "invalid rotation time (#{value.inspect})"]
    end

    return true
  end
end