Class: MetasploitDataModels::IPAddress::V4::Segmented
- Inherits:
-
Metasploit::Model::Base
- Object
- Metasploit::Model::Base
- MetasploitDataModels::IPAddress::V4::Segmented
- Extended by:
- Match::Child
- Includes:
- Comparable
- Defined in:
- app/models/metasploit_data_models/ip_address/v4/segmented.rb
Overview
Segmented.segment must be called in subclasses to set the Segmented.segment_class_name.
An IPv4 address that is composed of 4 #segments separated by '.'
.
Constant Summary collapse
- SEGMENT_COUNT =
The number of #segments
4
- SEPARATOR =
Separator between segments
'.'
Instance Attribute Summary collapse
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
-
.regexp ⇒ Regexp
Regular expression that matches the part of a string that represents a IPv4 segmented IP address format.
-
.segment(options = {}) ⇒ void
Sets up the Segmented.segment_class_name for the subclass.
-
.segment_class ⇒ Class
The
Class
used to parse each segment of the IPv4 address. -
.segment_class_name ⇒ String
The name of Segmented.segment_class.
-
.segment_count ⇒ Integer
The number of #segments.
Instance Method Summary collapse
-
#<=>(other) ⇒ 1, ...
Compare this segment IPv4 address to
other
. -
#segments ⇒ Array, []
Array of segments.
-
#segments=(segments) ⇒ Array
Set #segments.
-
#to_s ⇒ String
Segments joined with SEPARATOR.
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
36 37 38 |
# File 'app/models/metasploit_data_models/ip_address/v4/segmented.rb', line 36 def value @value end |
Class Method Details
.regexp ⇒ Regexp
Call segment with the segment_class_name before calling this method, as it uses segment_class to look
up the REGEXP
of the segment_class.
Regular expression that matches the part of a string that represents a IPv4 segmented IP address format.
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/models/metasploit_data_models/ip_address/v4/segmented.rb', line 69 def self.regexp unless @regexp separated_segment_count = SEGMENT_COUNT - 1 @regexp = %r{ (#{segment_class::REGEXP}#{Regexp.escape(SEPARATOR)}){#{separated_segment_count},#{separated_segment_count}} #{segment_class::REGEXP} }x end @regexp end |
.segment(options = {}) ⇒ void
This method returns an undefined value.
Sets up the segment_class_name for the subclass.
90 91 92 93 94 |
# File 'app/models/metasploit_data_models/ip_address/v4/segmented.rb', line 90 def self.segment(={}) .assert_valid_keys(:class_name) @segment_class_name = .fetch(:class_name) end |
.segment_class ⇒ Class
Call segment to set the segment_class_name before calling segment_class, which will attempt to String#constantize` segment_class_name.
The Class
used to parse each segment of the IPv4 address.
102 103 104 |
# File 'app/models/metasploit_data_models/ip_address/v4/segmented.rb', line 102 def self.segment_class @segment_class = segment_class_name.constantize end |
.segment_class_name ⇒ String
Call segment to set segment_class_name
The name of segment_class
111 112 113 |
# File 'app/models/metasploit_data_models/ip_address/v4/segmented.rb', line 111 def self.segment_class_name @segment_class_name end |
.segment_count ⇒ Integer
The number of #segments
118 119 120 |
# File 'app/models/metasploit_data_models/ip_address/v4/segmented.rb', line 118 def self.segment_count SEGMENT_COUNT end |
Instance Method Details
#<=>(other) ⇒ 1, ...
Compare this segment IPv4 address to other
.
132 133 134 135 136 137 138 139 |
# File 'app/models/metasploit_data_models/ip_address/v4/segmented.rb', line 132 def <=>(other) if other.is_a? self.class segments <=> other.segments else # The interface for <=> requires nil be returned if other is incomparable nil end end |
#segments ⇒ Array, []
Array of segments.
145 146 147 148 149 150 151 |
# File 'app/models/metasploit_data_models/ip_address/v4/segmented.rb', line 145 def segments if value.is_a? Array value else [] end end |
#segments=(segments) ⇒ Array
Set #segments.
157 158 159 |
# File 'app/models/metasploit_data_models/ip_address/v4/segmented.rb', line 157 def segments=(segments) @value = segments end |