Class: Droonga::MessageMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/droonga/message_matcher.rb

Overview

It checks whether the pattern matches against a message.

It provides the small language. Here is the pattern syntax.

  • PATTERN = [TARGET_PATH, OPERATOR, ARGUMENT*]
  • PATTERN = [PATTERN, LOGICAL_OPERATOR, PATTERN]
  • TARGET_PATH = "COMPONENT(.COMPONENT)*"
  • OPERATOR = :equal, :in, :include, :exist, :start_with (More operators may be added in the future. For example, :end_with and so on.)
  • ARGUMENT = OBJECT_DEFINED_IN_JSON
  • LOGICAL_OPERATOR = :or (:add will be added.)

For example:

["type", :equal, "search"]

matches to the following message:

{"type" => "search"}

Another example:

["body.output.limit", :equal, 10]

matches to the following message:

{
  "body" => {
    "output" => {
      "limit" => 10,
    },
  },
}

Instance Method Summary collapse

Constructor Details

#initialize(pattern) ⇒ MessageMatcher

Returns a new instance of MessageMatcher.

Parameters:

  • pattern (Array)

    The pattern to be matched against a message.



61
62
63
64
65
66
# File 'lib/droonga/message_matcher.rb', line 61

def initialize(pattern)
  path, operator, *arguments = pattern
  @path_components = path.split(".")
  @operator = operator
  @arguments = arguments
end

Instance Method Details

#match?(message) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
71
# File 'lib/droonga/message_matcher.rb', line 68

def match?(message)
  target = extract_target(message)
  apply_operator(target)
end