ExLedger.Automated (ex_ledger v0.6.0)

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)  -1

This 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

  1. Separates automated transactions (kind: :automated) from regular ones
  2. 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
  3. 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

posting()

@type posting() :: map()

transaction()

@type transaction() :: map()

Functions

apply_all(transactions)

@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.

apply_all_preserve_automated(transactions)

@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.

automated?(arg1)

@spec automated?(transaction()) :: boolean()

Checks if a transaction is an automated transaction.