Beancount.Directive protocol (beancount_ex v0.6.0)

Copy Markdown View Source

Protocol implemented by every Beancount directive struct.

A directive knows how to render itself into a fragment of valid Beancount text via to_bean/1. The top-level Beancount.Renderer is responsible for joining individual directive fragments into a complete .bean document.

Directive structs

Each module under Beancount.Directives documents its Beancount syntax, Elixir struct shape, and fields. See the Beancount language syntax.

Prefer Beancount.open/4, Beancount.transaction/6, and the other constructor functions in Beancount when building ledgers programmatically.

Summary

Types

t()

Any value implementing the Beancount.Directive protocol.

Functions

Render a single directive into Beancount text.

Types

t()

@type t() :: term()

Any value implementing the Beancount.Directive protocol.

Functions

to_bean(directive)

@spec to_bean(t()) :: iodata()

Render a single directive into Beancount text.

The returned value is iodata/0 without a trailing newline. The renderer takes care of separating directives.

Examples

iex> open = Beancount.open(~D[2026-01-01], "Assets:Bank", ["USD"])
iex> open |> Beancount.Directive.to_bean() |> IO.iodata_to_binary()
"2026-01-01 open Assets:Bank USD"