Skip to content

Instantly share code, notes, and snippets.

@simen
Created December 5, 2011 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save simen/1433530 to your computer and use it in GitHub Desktop.
Save simen/1433530 to your computer and use it in GitHub Desktop.
Match with constraint counting
"identity:7" => [1,2,4]
"realm:mittap" => [1,3,4]
"body:'Hello…' => [4]
1: rule: {identity: 7, realm: 'mittap'}, number_of_constraints: 2
2: rule: {identity: 7}, number_of_constraints: 1
3: rule: {identity: 8, realm: 'mittap'}, number_of_constraints: 2
4: rule: {identity: 7, realm: 'mittap', body: "Hello from number 7"}, number_of_constraints: 3
message = {identity: 7, body: "Hello from number 7"}
single_constraint_match = find_applicable_rules(message) => [1,2,4,1,3,4,4]
count_matches(single_constraint_match)
=> 1 => 2
2 => 1
3 => 1
4 => 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment