ExLedger.Parser.Helpers (ex_ledger v0.6.1)

Shared helper functions used across parser modules.

Summary

Functions

Returns all postings from a list of transactions.

Ensures a numeric string has exactly two decimal places.

Extracts the value from a posting's amount.

Extracts the currency from a posting's amount.

Returns all postings from regular transactions only.

Checks if a transaction is a regular transaction (has a date and is not automated/periodic).

Filters transactions to only include regular transactions (not automated/periodic).

Converts a value to Decimal.

Returns a sorted list of unique items.

Functions

all_postings(transactions)

@spec all_postings([map()]) :: [map()]

Returns all postings from a list of transactions.

ensure_two_decimals(str)

@spec ensure_two_decimals(String.t()) :: String.t()

Ensures a numeric string has exactly two decimal places.

Examples

iex> ensure_two_decimals("42")
"42.00"

iex> ensure_two_decimals("42.5")
"42.50"

iex> ensure_two_decimals("42.50")
"42.50"

format_amount_for_currency(value, currency, currency_position \\ :leading)

@spec format_amount_for_currency(
  Decimal.t() | number(),
  String.t() | nil,
  atom() | nil
) :: String.t()

Formats an amount value for a given currency.

posting_amount_value(arg1)

@spec posting_amount_value(map()) :: number() | nil

Extracts the value from a posting's amount.

posting_currency(arg1)

@spec posting_currency(map()) :: String.t() | nil

Extracts the currency from a posting's amount.

regular_postings(transactions)

@spec regular_postings([map()]) :: [map()]

Returns all postings from regular transactions only.

regular_transaction?(transaction)

@spec regular_transaction?(map()) :: boolean()

Checks if a transaction is a regular transaction (has a date and is not automated/periodic).

regular_transactions(transactions)

@spec regular_transactions([map()]) :: [map()]

Filters transactions to only include regular transactions (not automated/periodic).

to_decimal(d)

@spec to_decimal(Decimal.t() | number()) :: Decimal.t()

Converts a value to Decimal.

Accepts Decimal, float, or integer values.

uniq_sort(items)

@spec uniq_sort([any()]) :: [any()]

Returns a sorted list of unique items.