module MetasploitDataModels::IPAddress::Range
Common behavior for ranges under {MetasploitDataModels::IPAddress}, including ranges of addresses and segments.
Constants
- SEPARATOR
Separator between the {#begin} and {#end} in the formatted value.
Attributes
@!attribute value
The range. @return [Range<Object, Objectr>] Range with {ClassMethods#extreme_class} instances for `Range#begin` and `Range#end`. @return [String] if `formatted_value` cannot be parsed into a Range.
Public Instance Methods
Begin of segment range.
@return [MetasploitDataModels::IPAddress::V4::NMAP::Segment::Number] if {#value} is a `Range`. @return [nil] if {#value} is not a `Range`.
# File lib/metasploit_data_models/ip_address/range.rb, line 116 def begin if value.respond_to? :begin value.begin end end
End of segment range.
@return [MetasploitDataModels::IPAddress::V4::NMAP::Segment::Number] if {#value} is a `Range`. @return [nil] if {#value} is not a `Range`.
# File lib/metasploit_data_models/ip_address/range.rb, line 126 def end if value.respond_to? :end value.end end end
This range as a string. Equivalent to the original `formatted_value` passed to {#value}.
@return [String]
# File lib/metasploit_data_models/ip_address/range.rb, line 135 def to_s "#{self.begin}#{SEPARATOR}#{self.end}" end
Sets {#value} by breaking up the range into its begin and end Integers.
@param formatted_value [#to_s] @return [Range<Integer, Integer>] if {SEPARATOR} is used and both extremes are Integers. @return [#to_s] `formatted_value` if it could not be converted
# File lib/metasploit_data_models/ip_address/range.rb, line 144 def value=(formatted_value) formatted_extremes = formatted_value.to_s.split(SEPARATOR, 2) extremes = formatted_extremes.map { |formatted_extreme| self.class.extreme_class.new(value: formatted_extreme) } begin @value = Range.new(*extremes) rescue ArgumentError @value = formatted_value end end
Private Instance Methods
Validates that {#begin} and {#end} are valid.
@return [void]
# File lib/metasploit_data_models/ip_address/range.rb, line 163 def extremes_valid [:begin, :end].each do |extreme_name| extreme_value = send(extreme_name) unless extreme_value.respond_to?(:valid?) && extreme_value.valid? errors.add(extreme_name, :invalid) end end end
Validates that {#begin} is `<=` {#end}.
@return [void]
# File lib/metasploit_data_models/ip_address/range.rb, line 176 def order if self.begin && self.end && self.begin > self.end errors.add(:value, :order, begin: self.begin, end: self.end) end