Class: Droonga::MessageMatcher
- Inherits:
-
Object
- Object
- Droonga::MessageMatcher
- 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
-
#initialize(pattern) ⇒ MessageMatcher
constructor
A new instance of MessageMatcher.
- #match?(message) ⇒ Boolean
Constructor Details
#initialize(pattern) ⇒ MessageMatcher
Returns a new instance of MessageMatcher.
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
68 69 70 71 |
# File 'lib/droonga/message_matcher.rb', line 68 def match?() target = extract_target() apply_operator(target) end |