Sha256: 459265531de5f998e3df378a255efd3e13fa3ec154f1e2ee758fbc96dec4c916

Contents?: true

Size: 1014 Bytes

Versions: 26

Compression:

Stored size: 1014 Bytes

Contents

# Concerns type casting of a raw value to an `Integer`.
module Metasploit::Model::Search::Operation::Integer::Value
  #
  # Attributes
  #

  # @!attribute [r] value_before_type_cast
  #   The formatted version of {#value} before it was type cast when calling {#value=}.
  #
  #   @return [Object]
  attr_reader :value_before_type_cast

  #
  # Methods
  #

  # Sets {Metasploit::Model::Search::Operation::Base#value} by type casting String to Integer.
  #
  # @param formatted_value [#to_s]
  # @return [Integer] if `formatted_value` contains only an Integer#to_s
  # @return [#to_s] `formatted_value` if it does not contain an Integer#to_s
  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
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
metasploit-model-0.27.3 lib/metasploit/model/search/operation/integer/value.rb
metasploit-model-0.27.3-java lib/metasploit/model/search/operation/integer/value.rb
metasploit-model-0.27.2 lib/metasploit/model/search/operation/integer/value.rb
metasploit-model-0.27.2-java lib/metasploit/model/search/operation/integer/value.rb
metasploit-model-0.27.1 lib/metasploit/model/search/operation/integer/value.rb
metasploit-model-0.27.1-java lib/metasploit/model/search/operation/integer/value.rb
metasploit-model-0.27.0 lib/metasploit/model/search/operation/integer/value.rb
metasploit-model-0.27.0-java lib/metasploit/model/search/operation/integer/value.rb
metasploit-model-0.27.0.pre.dep.pre.railties lib/metasploit/model/search/operation/integer/value.rb
metasploit-model-0.26.1-java lib/metasploit/model/search/operation/integer/value.rb
metasploit-model-0.26.1 lib/metasploit/model/search/operation/integer/value.rb
metasploit-model-0.25.7 lib/metasploit/model/search/operation/integer/value.rb
metasploit-model-0.25.7-java lib/metasploit/model/search/operation/integer/value.rb
metasploit-model-0.25.6 lib/metasploit/model/search/operation/integer/value.rb
metasploit-model-0.25.6-java lib/metasploit/model/search/operation/integer/value.rb
metasploit-model-0.25.3 lib/metasploit/model/search/operation/integer/value.rb
metasploit-model-0.25.3-java lib/metasploit/model/search/operation/integer/value.rb
metasploit-model-0.25.2 lib/metasploit/model/search/operation/integer/value.rb
metasploit-model-0.25.2-java lib/metasploit/model/search/operation/integer/value.rb
metasploit-model-0.25.1 lib/metasploit/model/search/operation/integer/value.rb