Module: MetasploitDataModels::IPAddress::CIDR::ClassMethods
- Includes:
- Match::Child
- Defined in:
- lib/metasploit_data_models/ip_address/cidr.rb
Overview
Class methods added to the including Class
.
Instance Attribute Summary collapse
-
#address_class ⇒ Object
Returns the value of attribute address_class.
Instance Method Summary collapse
-
#cidr(options = {}) ⇒ Object
Sets up the address class and allowed #maximum_prefix_length for the including
Class
. -
#match_regexp ⇒ Regexp
Regular expression that matches a string that contains only a CIDR IP address.
-
#maximum_prefix_length ⇒ Integer
The maximum number of bits in a prefix for the #address_class.
-
#regexp ⇒ Regexp
Regular expression that matches a portion of string that contains a CIDR IP address.
Methods included from Match::Child
Instance Attribute Details
#address_class ⇒ Object
Returns the value of attribute address_class.
66 67 68 |
# File 'lib/metasploit_data_models/ip_address/cidr.rb', line 66 def address_class @address_class end |
Instance Method Details
#cidr(options = {}) ⇒ Object
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
.
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/metasploit_data_models/ip_address/cidr.rb', line 80 def cidr(={}) .assert_valid_keys(:address_class) @address_class = .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 |
#match_regexp ⇒ Regexp
Regular expression that matches a string that contains only a CIDR IP address.
100 101 102 |
# File 'lib/metasploit_data_models/ip_address/cidr.rb', line 100 def match_regexp @match_regexp ||= /\A#{regexp}\z/ end |
#maximum_prefix_length ⇒ Integer
The maximum number of bits in a prefix for the #address_class.
107 108 109 |
# 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 |
#regexp ⇒ Regexp
Regular expression that matches a portion of string that contains a CIDR IP address.
114 115 116 |
# 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 |