ExLedger.Predicate.AmountExpr (ex_ledger v0.6.0)

Evaluates amount expressions in automated transaction postings.

Amount expressions can be:

  • Fixed amounts: $50.00, 100 EUR - used as-is
  • Multipliers: 1, -1, 0.10 - multiply the matched posting's amount

The distinction is based on whether a currency is specified:

  • With currency → fixed amount
  • Without currency (bare number) → multiplier

Examples

# Fixed amount - always $25
iex> AmountExpr.evaluate(%{value: Decimal.new("25"), currency: "$"}, matched_amount)
%{value: Decimal.new("25"), currency: "$"}

# Multiplier -1 - negate matched amount
iex> AmountExpr.evaluate(%{value: Decimal.new("-1"), currency: nil}, %{value: Decimal.new("50"), currency: "$"})
%{value: Decimal.new("-50"), currency: "$"}

# Multiplier 0.10 - 10% of matched amount
iex> AmountExpr.evaluate(%{value: Decimal.new("0.10"), currency: nil}, %{value: Decimal.new("100"), currency: "$"})
%{value: Decimal.new("10.00"), currency: "$"}

Summary

Functions

Evaluates an amount expression against a matched posting's amount.

Determines if an amount expression is a fixed amount or a multiplier.

Determines if an amount expression is a multiplier.

Types

amount()

@type amount() :: %{
  value: Decimal.t(),
  currency: String.t() | nil,
  currency_position: :leading | :trailing | nil
}

Functions

evaluate(expr_amount, matched_amount)

@spec evaluate(amount() | nil, amount() | nil) :: amount() | nil

Evaluates an amount expression against a matched posting's amount.

Parameters

  • expr_amount - The amount from the automated transaction posting
  • matched_amount - The amount from the posting that matched the predicate

Returns

A new amount map with the calculated value and appropriate currency.

is_fixed_amount?(arg1)

@spec is_fixed_amount?(String.t() | nil) :: boolean()

Determines if an amount expression is a fixed amount or a multiplier.

  • Fixed: has a currency (e.g., $50, 100 EUR)
  • Multiplier: no currency (e.g., 1, -1, 0.10)

is_multiplier?(arg1)

@spec is_multiplier?(amount()) :: boolean()

Determines if an amount expression is a multiplier.