ExLedger.Predicate.Evaluator (ex_ledger v0.6.1)
Evaluates predicate ASTs against transaction/posting contexts.
Takes an AST produced by ExLedger.Predicate.Parser and evaluates it
against a context containing transaction and posting data.
Example
iex> ast = {:account_regex, ~r/^Expenses:/}
iex> ctx = Evaluator.context(transaction, posting)
iex> Evaluator.matches?(ast, ctx)
true
Summary
Functions
Creates an evaluation context from a transaction and posting.
Parses a predicate string and evaluates it against a context.
Finds all postings in a transaction that match a predicate.
Evaluates a predicate AST against an evaluation context.
Types
@type ast() :: ExLedger.Predicate.Parser.ast()
Functions
@spec context(map(), map(), keyword()) :: ExLedger.Predicate.Evaluator.Context.t()
Creates an evaluation context from a transaction and posting.
Options
:posting_index- Index of the posting in the transaction (default: 0)
@spec evaluate(String.t(), ExLedger.Predicate.Evaluator.Context.t()) :: {:ok, boolean()} | {:error, term()}
Parses a predicate string and evaluates it against a context.
Combines Parser.parse/1 and matches?/2 for convenience.
@spec find_matching_postings(String.t() | ast(), map()) :: {:ok, [{map(), non_neg_integer()}]} | {:error, term()}
Finds all postings in a transaction that match a predicate.
Returns a list of {posting, index} tuples for matching postings.
@spec matches?(ast(), ExLedger.Predicate.Evaluator.Context.t()) :: boolean()
Evaluates a predicate AST against an evaluation context.
Returns true if the predicate matches, false otherwise.