Module: Metasploit::Model::Search::Operation

Extended by:
ActiveSupport::Autoload
Defined in:
lib/metasploit/model/search/operation.rb

Overview

Namespace for search operations. Operation.parse acts as a factory to parse a String and return a type-specific operation.

Defined Under Namespace

Modules: Group, Value Classes: Association, Base, Boolean, Date, Integer, Null, Set, String

Class Method Summary collapse

Class Method Details

.parse(options = {}) ⇒ Metasploit::Model::Search::Operation::Base+

Returns operation(s) parsed from the formatted operation.

Parameters:

  • options (Hash{Symbol => Object}) (defaults to: {})

Options Hash (options):

  • :query (Metasploit::Module::Search::Query)

    The query that the parsed operation is a part.

  • :formatted_operation (String)

    A ':' string.

Returns:

Raises:

  • (KeyError)

    unless :formatted_operation is given.

  • (KeyError)

    unless :query is given.


24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/metasploit/model/search/operation.rb', line 24

def self.parse(options={})
  formatted_operation = options.fetch(:formatted_operation)
  query = options.fetch(:query)

  formatted_operator, formatted_value = formatted_operation.split(':', 2)
  operator = query.parse_operator(formatted_operator)

  # formatted_value will be nil if formatted_operation did not contain a ':', it should be treated the same
  # as nothing after the ':'.
  formatted_value ||= ''
  operation_or_operations = operator.operate_on(formatted_value)

  operation_or_operations
end