Sha256: 7444c452e72c694169d1557ea0e0b5cc1c0dbf445c73b37c77ce680d28f94eb5

Contents?: true

Size: 1.12 KB

Versions: 124

Compression:

Stored size: 1.12 KB

Contents

# Search operation on a `Range`.
class MetasploitDataModels::Search::Operation::Range < Metasploit::Model::Search::Operation::Base
  #
  # CONSTANTS
  #

  # Separates beginning from end of the range.
  SEPARATOR = '-'

  #
  # Validation
  #

  validate :ordered
  validate :range

  #
  # Instance Methods
  #

  # Sets `#value` to a `Range` composed by separating `formatted_value` by `-`.
  #
  # @param formatted_value [#to_s]
  # @return [Range<String>]
  def value=(formatted_value)
    range_arguments = formatted_value.to_s.split(SEPARATOR, 2)

    begin
      @value = Range.new(*range_arguments)
    rescue ArgumentError
      @value = formatted_value
    end

    @value
  end

  private

  # Validates that `#value` is a `Range` with `Range#begin` less than or equal to `Range#begin`
  #
  # @return [void]
  def ordered
    if value.is_a?(Range) && value.begin > value.end
      errors.add(:value, :order, begin: value.begin.inspect, end: value.end.inspect)
    end
  end

  # Validates that `#value` is a `Range`
  #
  # @return [void]
  def range
    unless value.is_a? Range
      errors.add(:value, :range)
    end
  end
end

Version data entries

124 entries across 124 versions & 2 rubygems

Version Path
wg-metasploit_data_models-4.1.4.02 app/models/metasploit_data_models/search/operation/range.rb
metasploit_data_models-6.0.5 app/models/metasploit_data_models/search/operation/range.rb
metasploit_data_models-6.0.4 app/models/metasploit_data_models/search/operation/range.rb
metasploit_data_models-6.0.3 app/models/metasploit_data_models/search/operation/range.rb
metasploit_data_models-6.0.2 app/models/metasploit_data_models/search/operation/range.rb
metasploit_data_models-6.0.1 app/models/metasploit_data_models/search/operation/range.rb
metasploit_data_models-6.0.0 app/models/metasploit_data_models/search/operation/range.rb
metasploit_data_models-5.0.6 app/models/metasploit_data_models/search/operation/range.rb
metasploit_data_models-5.0.5 app/models/metasploit_data_models/search/operation/range.rb
metasploit_data_models-5.0.4 app/models/metasploit_data_models/search/operation/range.rb
metasploit_data_models-5.0.3 app/models/metasploit_data_models/search/operation/range.rb
metasploit_data_models-5.0.2 app/models/metasploit_data_models/search/operation/range.rb
metasploit_data_models-5.0.1 app/models/metasploit_data_models/search/operation/range.rb
metasploit_data_models-5.0.0 app/models/metasploit_data_models/search/operation/range.rb
metasploit_data_models-4.1.4 app/models/metasploit_data_models/search/operation/range.rb
metasploit_data_models-4.1.3 app/models/metasploit_data_models/search/operation/range.rb
metasploit_data_models-4.1.2 app/models/metasploit_data_models/search/operation/range.rb
metasploit_data_models-4.1.1 app/models/metasploit_data_models/search/operation/range.rb
metasploit_data_models-4.1.0 app/models/metasploit_data_models/search/operation/range.rb
metasploit_data_models-4.0.2 app/models/metasploit_data_models/search/operation/range.rb