Class: MetasploitDataModels::Search::Operation::Port::Range

Inherits:
Range
  • Object
show all
Defined in:
app/models/metasploit_data_models/search/operation/port/range.rb

Overview

Search operation on an attribute that holds a port number and is being search with a range of port numbers. The range is specified as <min>-<max> with <min> being less than <max> and both being within the valid port range.

Constant Summary

Constants inherited from Range

Range::SEPARATOR

Instance Method Summary collapse

Instance Method Details

#value=(formatted_value) ⇒ Object

Sets #value to a range of ports.

Parameters:

  • formatted_value (#to_s)

    '\d+-\d+'


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/models/metasploit_data_models/search/operation/port/range.rb', line 18

def value=(formatted_value)
  super(formatted_value)

  # could not be a `Range` if super conversion failed
  # setters return the argument, not the return value from the method, so access `#value` directly
  if value.is_a? Range
    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.
      integer_begin = Integer(value.begin.to_s)
      integer_end = Integer(value.end.to_s)
    rescue ArgumentError
      # setter returned is ignored in MRI, but do it anyway for other implementation
      @value
    else
      @value = Range.new(integer_begin, integer_end)
    end
  else
    # setter returned is ignored in MRI, but do it anyway for other implementation
    # return unconvertible value from `super`
    @value
  end
end