ABSmartly.Matcher (ABSmartly v1.0.0)

Copy Markdown View Source

Audience matcher for experiment targeting.

Summary

Functions

Evaluate audience filter against attributes.

Return the action of the first rule that matches environment and attributes: {:variant, variant} for an assign rule, {:split, fractions} for a split rule, or nil when no rule matches.

Parse an experiment's assignmentRules JSON into its list of rules.

Functions

evaluate(filter, attributes)

Evaluate audience filter against attributes.

Returns:

  • nil if filter is nil
  • true if filter is empty map (matches all)
  • result of filter evaluation otherwise
  • nil when the filter value is not a list or map
  • false for invalid filter structures (fail closed)

Examples

iex> evaluate(nil, %{})
nil

iex> evaluate(%{}, %{})
true

iex> evaluate(%{"filter" => [%{"value" => true}]}, %{})
true

iex> evaluate(%{"filter" => [%{"value" => false}]}, %{})
false

evaluate_rules(rules, environment, attributes)

Return the action of the first rule that matches environment and attributes: {:variant, variant} for an assign rule, {:split, fractions} for a split rule, or nil when no rule matches.

Mirrors the JavaScript SDK's evaluateParsedRules (src/matcher.ts): a rule whose action is invalid (unknown type, non-integer variant, or percentages that are not non-negative numbers summing to 100) is skipped. An environments list, when present, must contain environment unless it is empty. Absent conditions always match; otherwise they must be an object that evaluates to true. Bounds checking the action is the caller's job.

parse_rules(rules)

Parse an experiment's assignmentRules JSON into its list of rules.

Returns nil when the value is absent, not valid JSON or not an object with a rules list, in which case the experiment has no rules.