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

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

Classes: 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.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/metasploit/model/search/operation.rb', line 14

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