module MetasploitDataModels::IPAddress::CIDR::ClassMethods
Class methods added to the including `Class`.
Attributes
@!attribute #address_class
The Class` whose instance are usd for {MetasploitDataModels::IPAddress::CIDR#address}. @return [Class]
Public Instance Methods
@note `address_class` must respond to `#segment_class` and `#segment_count` so {#maximum_prefix_length} can be
calculated.
Sets up the address class and allowed {#maximum_prefix_length} for the including `Class`.
@param options [Hash{Symbol => Class}] @option options [Class, segment_class, segment_count] :address_class The `Class` whose instances will be used
for {#address}.
# File lib/metasploit_data_models/ip_address/cidr.rb, line 80 def cidr(options={}) options.assert_valid_keys(:address_class) @address_class = options.fetch(:address_class) # # Validations # validates :prefix_length, numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: maximum_prefix_length } end
Regular expression that matches a string that contains only a CIDR IP address.
@return [Regexp]
# File lib/metasploit_data_models/ip_address/cidr.rb, line 100 def match_regexp @match_regexp ||= /\A#{regexp}\z/ end
The maximum number of bits in a prefix for the {#address_class}.
@return [Integer] the number of bits across all segments of {#address_class}.
# File lib/metasploit_data_models/ip_address/cidr.rb, line 107 def maximum_prefix_length @maximum_prefix_length ||= address_class.segment_count * address_class.segment_class.bits end
Regular expression that matches a portion of string that contains a CIDR IP address.
@return [Regexp]
# File lib/metasploit_data_models/ip_address/cidr.rb, line 114 def regexp @regexp ||= /(?<address>#{address_class.regexp})#{Regexp.escape(SEPARATOR)}(?<prefix_length>\d+)/ end