ExLedger.LedgerParser (ex_ledger v0.5.6)
Parser for ledger-cli format files.
This module serves as the main entry point and facade for ledger parsing functionality. Core parsing is delegated to specialized submodules under ExLedger.Parser.
Summary
Functions
Calculates the balance for each account by summing all postings.
Formats a balance report for transactions with optional filtering and output options.
Checks whether the ledger file at the given path parses successfully.
Checks a ledger file and returns {:ok, :valid} or {:error, reason}.
Checks whether the given ledger string parses successfully.
Formats account postings as a register report.
Formats account balances as a balance report.
Formats transactions into ledger-compatible output.
Gets all postings for a specific account with running balance.
Parses a ledger file with support for include directives and account declarations.
Builds a register view of postings with running balances.
Types
@type account_declaration() :: ExLedger.Parser.Core.account_declaration()
@type amount() :: ExLedger.Parser.Core.amount()
@type commodity_definition() :: ExLedger.Parser.Core.commodity_definition()
@type ledger_error() :: ExLedger.Parser.Core.ledger_error()
@type parse_error() :: ExLedger.Parser.Core.parse_error()
@type parse_error_detail() :: ExLedger.Parser.Core.parse_error_detail()
@type parse_result() :: %{ transactions: [transaction()], accounts: %{required(String.t()) => atom()}, prices: [price_directive()], commodities: %{required(String.t()) => commodity_definition()} }
@type posting() :: ExLedger.Parser.Core.posting()
@type price_db() :: ExLedger.Parser.Price.price_db()
@type price_directive() :: ExLedger.Parser.Core.price_directive()
@type time_entry() :: ExLedger.Parser.Timeclock.time_entry()
@type transaction() :: ExLedger.Parser.Core.transaction()
Functions
@spec balance([transaction()] | transaction()) :: %{required(String.t()) => [map()]}
Calculates the balance for each account by summing all postings.
balance_by_period(transactions, group_by \\ "none", start_date \\ nil, end_date \\ nil, account_filter \\ nil)
@spec balance_report([transaction()], Regex.t() | nil, keyword()) :: String.t()
Formats a balance report for transactions with optional filtering and output options.
@spec budget_report([transaction()], Date.t()) :: [map()]
@spec build_xact([transaction()], Date.t(), String.t()) :: {:ok, String.t()} | {:error, atom()}
Checks whether the ledger file at the given path parses successfully.
@spec check_file_with_error(String.t()) :: {:ok, :valid} | {:error, ledger_error()}
Checks a ledger file and returns {:ok, :valid} or {:error, reason}.
Checks whether the given ledger string parses successfully.
See ExLedger.Parser.Accounts.extract_account_declarations/1.
See ExLedger.Parser.Declarations.extract_commodity_declarations/1.
See ExLedger.Parser.Declarations.extract_full_commodity_declarations/1.
See ExLedger.Parser.Declarations.extract_payee_declarations/1.
See ExLedger.Parser.Declarations.extract_tag_declarations/1.
@spec forecast_balance([transaction()], pos_integer()) :: %{ required(String.t()) => [map()] }
Formats account postings as a register report.
Formats account balances as a balance report.
@spec format_transactions([transaction()]) :: String.t()
Formats transactions into ledger-compatible output.
@spec get_account_postings([transaction()], String.t()) :: [map()]
Gets all postings for a specific account with running balance.
@spec parse_ledger( String.t(), keyword() ) :: {:ok, parse_result()} | {:error, ledger_error()}
Parses a ledger file with support for include directives and account declarations.
Returns a map containing:
:transactions- List of parsed transactions:accounts- Map of account names to their types:prices- List of price directives:commodities- Map of commodity symbols to their definitions
@spec register([transaction()], Regex.t() | nil) :: [map()]
Builds a register view of postings with running balances.
@spec select([transaction()], String.t()) :: {:ok, [String.t()], [map()]} | {:error, atom()}
@spec stats([transaction()]) :: map()