class MetasploitDataModels::IPAddress::V4::Segment::Nmap::List

A comma separated list of {MetasploitDataModels::IPAddress::V4::Segment::Single segment numbers} and {MetasploitDataModels::IPAddress::V4::Segment::Nmap::Range range of segment numbers} making up one segment of {MetasploitDataModels::IPAddress::V4::Nmap}.

Constants

MATCH_REGEXP

Matches exactly an Nmap comma separated list of segment numbers and ranges.

RANGE_OR_NUMBER_REGEXP

Either an individual {MetasploitDataModels::IPAddress::V4::Segment::Single segment number} or a {MetasploitDataModels::IPAddress::V4::Segment::Nmap::Range segment range}.

REGEXP

Segment of an NMAP address, composed of comma separated {RANGE_OR_NUMBER_REGEXP segment numbers or ranges}.

SEPARATOR

Separator between number or ranges

Attributes

value[R]

@!attribute value

The NMAP IPv4 octect range.

@return [Array<MetasploitDataModels::IPAddress::V4::Segment::Number, MetasploitDataModels::IPAddress::V4::Segment::Range>]
  number and range in the order they appeared in formatted value.

Public Instance Methods

to_s() click to toggle source

@return [String]

# File app/models/metasploit_data_models/ip_address/v4/segment/nmap/list.rb, line 74
def to_s
  if value.is_a? Array
    value.map(&:to_s).join(SEPARATOR)
  else
    value.to_s
  end
end
value=(formatted_value) click to toggle source

Set {#value} to an `Array` of segment numbers and ranges.

@param formatted_value [#to_s] @return [Array<MetasploitDataModels::IPAddress::V4::Segment::Single, MetasploitDataModels::IPAddress::V4::Segment::Nmap::Range>] a parsed `Array` of segment numbers and ranges. @return [#to_s] if `formatted_value` does not match {MATCH_REGEXP}.

# File app/models/metasploit_data_models/ip_address/v4/segment/nmap/list.rb, line 87
def value=(formatted_value)
  string = formatted_value.to_s
  match = MATCH_REGEXP.match(string)

  if match
    ranges_or_numbers = string.split(SEPARATOR)

    @value = ranges_or_numbers.map { |range_or_number|
      match_child(range_or_number) || range_or_number
    }
  else
    @value = formatted_value
  end
end

Private Instance Methods

value_elements_valid() click to toggle source

Validates that {#value}'s elements are all valid.

@return [void]

# File app/models/metasploit_data_models/ip_address/v4/segment/nmap/list.rb, line 107
def value_elements_valid
  if value.is_a? Array
    value.each_with_index do |element, index|
      unless element.valid?
        errors.add(:value, :element, element: element, index: index)
      end
    end
  end
end
value_is_array() click to toggle source

Validates that {#value} is an `Array`.

@return [void]

# File app/models/metasploit_data_models/ip_address/v4/segment/nmap/list.rb, line 120
def value_is_array
  unless value.is_a? Array
    errors.add(:value, :array)
  end
end