Module: Metasploit::Model::Search::Operation::Value::Integer

Included in:
Integer, Set::Integer
Defined in:
lib/metasploit/model/search/operation/value/integer.rb

Overview

Concerns type casting of a raw value to an Integer.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#value_before_type_castObject (readonly)

Returns the value of attribute value_before_type_cast


11
12
13
# File 'lib/metasploit/model/search/operation/value/integer.rb', line 11

def value_before_type_cast
  @value_before_type_cast
end

Instance Method Details

#value=(formatted_value) ⇒ Integer, #to_s

Sets Base#value by type casting String to Integer.

Parameters:

  • formatted_value (#to_s)

Returns:

  • (Integer)

    if formatted_value contains only an Integer#to_s

  • (#to_s)

    formatted_value if it does not contain an Integer#to_s


22
23
24
25
26
27
28
29
30
31
32
# File 'lib/metasploit/model/search/operation/value/integer.rb', line 22

def value=(formatted_value)
  @value_before_type_cast = formatted_value

  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.
    @value = Integer(formatted_value.to_s)
  rescue ArgumentError
    @value = formatted_value
  end
end