Class: Masscan::Command::Shards Private
- Inherits:
-
CommandMapper::Types::Str
- Object
- CommandMapper::Types::Str
- Masscan::Command::Shards
- 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 --shards
option.
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
--shards
values. %r{\A\d+/\d+\z}
Instance Method Summary collapse
-
#format(value) ⇒ String
private
Formats a shards value into a String.
-
#validate(value) ⇒ true, (false, String)
private
Validates a shards value.
Instance Method Details
#format(value) ⇒ 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.
Formats a shards value into a String.
359 360 361 362 363 364 365 366 |
# File 'lib/masscan/command.rb', line 359 def format(value) case value when Array "#{value[0]}/#{value[1]}" else super(value) end end |
#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 shards value.
319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
# File 'lib/masscan/command.rb', line 319 def validate(value) case value when Array unless value.length == 2 return [false, "must contain two elements (#{value.inspect})"] end unless (value[0].kind_of?(Integer) && value[1].kind_of?(Integer)) return [false, "shard values must be Integers (#{value.inspect})"] end return true when Rational return true else valid, = super(value) unless valid return [valid, ] end string = value.to_s unless string =~ REGEXP return [false, "invalid shards value (#{value.inspect})"] end return true end end |