ExLedger.Automated (ex_ledger v0.6.1)
Applies automated transactions to generate derived postings.
Automated transactions are rules that match against regular transactions and generate additional postings or add metadata/tags.
Example
= /Expenses:Food/
(Budget:Food) -1This rule matches any posting to an Expenses:Food account and generates
a virtual unbalanced posting to Budget:Food with the negated amount.
Usage
{:ok, result} = LedgerParser.parse_ledger(input)
transactions = Automated.apply_all(result.transactions)How it works
- Separates automated transactions (kind: :automated) from regular ones
- For each regular transaction:
- For each posting in the transaction:
- For each automated transaction:
- Parse the predicate (cached)
- Evaluate predicate against the posting
- If match: generate derived postings OR apply metadata/tags
- For each automated transaction:
- For each posting in the transaction:
- Returns transactions with derived postings added
Matching behavior
- Predicates are evaluated at the posting level
- Each matching posting can trigger generation of new postings
- Automated transactions do NOT chain (no recursion)
- Multiple automated transactions apply in file order
Summary
Functions
Applies all automated transactions to regular transactions.
Applies automated transactions and returns both regular and automated.
Checks if a transaction is an automated transaction.
Types
Functions
@spec apply_all([transaction()]) :: [transaction()]
Applies all automated transactions to regular transactions.
Takes a list of all transactions (both regular and automated) and returns a new list with derived postings added to matching regular transactions.
Automated transactions are filtered out from the result.
@spec apply_all_preserve_automated([transaction()]) :: [transaction()]
Applies automated transactions and returns both regular and automated.
Unlike apply_all/1, this preserves automated transactions in the output.
@spec automated?(transaction()) :: boolean()
Checks if a transaction is an automated transaction.