module MetasploitDataModels::IPAddress::CIDR
Common behavior for Class-InterDomain Routing (`<address>/<prefix-length>`) notation under {MetasploitDataModels::IPAddress},
Constants
- SEPARATOR
Separator between the {#address} and {#prefix_length}
Attributes
address[R]
@!attribute address
The IP address being masked by {#prefix_length} `1` bits. @return [Object] an instance of {address_class}
prefix_length[R]
@!attribute #prefix_length
The significant number of bits in {#address}. @return [Integer] number of `1` bits in the netmask of {#address}
Public Instance Methods
address=(formatted_address)
click to toggle source
Set {#address}.
@param formatted_address [#to_s]
# File lib/metasploit_data_models/ip_address/cidr.rb, line 126 def address=(formatted_address) @address = self.class.address_class.new(value: formatted_address) end
prefix_length=(formatted_prefix_length)
click to toggle source
Set {#prefix_length}.
@param formatted_prefix_length [#to_s]
# File lib/metasploit_data_models/ip_address/cidr.rb, line 133 def prefix_length=(formatted_prefix_length) @prefix_length_before_type_cast = formatted_prefix_length begin # use Integer() instead of String#to_i as String#to_i will ignore trailing letters (i.e. '1two' -> 1) and turn all # string without an integer in it to 0. @prefix_length = Integer(formatted_prefix_length.to_s) rescue ArgumentError @prefix_length = formatted_prefix_length end end
prefix_length_before_type_cast()
click to toggle source
The formatted_prefix_length passed to {#prefix_length=}
@return [#to_s]
# File lib/metasploit_data_models/ip_address/cidr.rb, line 148 def prefix_length_before_type_cast @prefix_length_before_type_cast end
value=(formatted_value)
click to toggle source
Parses the `formatted_value` into an {#address} and {#prefix_length}.
@param formatted_value [#to_s]
# File lib/metasploit_data_models/ip_address/cidr.rb, line 155 def value=(formatted_value) formatted_address, formatted_prefix_length = formatted_value.to_s.split(SEPARATOR, 2) self.address = formatted_address self.prefix_length = formatted_prefix_length [address, prefix_length] end
Private Instance Methods
address_valid()
click to toggle source
Validates that {#address} is valid.
@return [void]
# File lib/metasploit_data_models/ip_address/cidr.rb, line 169 def address_valid if address && !address.valid? errors.add(:address, :invalid) end end