CFONB.Encode (CFONB v0.2.0)

Copy Markdown View Source

Low-level fixed-width field formatting for emitting CFONB records — the symmetric counterpart of the decoders in CFONB.

Two alignment rules, per the CFONB brochure:

  • numeric zones are right-aligned and zero-filled (numeric/2),
  • alphanumeric zones are left-aligned and space-filled (alpha/2), restricted to the permitted character set (sanitize/1).

Amounts are encoded as unsigned integer cents (centimes/2) — note this is a different encoding from the signed "montant" of the 120 statement format. Functions raise ArgumentError on data that cannot be represented (negative amount, more than two decimals, numeric overflow); callers are expected to validate user input first.

Summary

Functions

Formats an alphanumeric zone: sanitized, left-aligned, space-filled, and truncated to len.

A reserved zone of len spaces.

Encodes a euro %Decimal{} amount as unsigned integer cents, right-aligned and zero-filled to len (default 16). Raises on a negative amount or on more than two decimal places.

Formats a settlement date as JJMMA — day, month, and the single trailing digit of the year, per the CFONB 160 spec. A nil date yields five spaces.

Formats a numeric zone: right-aligned, zero-filled to len. Accepts an integer or a digit string. Raises if the value does not fit in len.

Uppercases, strips accents, and replaces any character outside the permitted CFONB set with a space. nil becomes an empty string.

Whether the euro amount is representable as a whole number of cents (at most two decimal places). Single source of the precision rule used both by centimes/2 and by callers validating input up front.

Functions

alpha(value, len)

@spec alpha(String.t() | nil, pos_integer()) :: String.t()

Formats an alphanumeric zone: sanitized, left-aligned, space-filled, and truncated to len.

blank(len)

@spec blank(non_neg_integer()) :: String.t()

A reserved zone of len spaces.

centimes(amount, len \\ 16)

@spec centimes(Decimal.t(), pos_integer()) :: String.t()

Encodes a euro %Decimal{} amount as unsigned integer cents, right-aligned and zero-filled to len (default 16). Raises on a negative amount or on more than two decimal places.

date_jjmma(arg1)

@spec date_jjmma(Date.t() | nil) :: String.t()

Formats a settlement date as JJMMA — day, month, and the single trailing digit of the year, per the CFONB 160 spec. A nil date yields five spaces.

numeric(value, len)

@spec numeric(integer() | String.t(), pos_integer()) :: String.t()

Formats a numeric zone: right-aligned, zero-filled to len. Accepts an integer or a digit string. Raises if the value does not fit in len.

sanitize(value)

@spec sanitize(String.t() | nil) :: String.t()

Uppercases, strips accents, and replaces any character outside the permitted CFONB set with a space. nil becomes an empty string.

whole_cents?(amount)

@spec whole_cents?(Decimal.t()) :: boolean()

Whether the euro amount is representable as a whole number of cents (at most two decimal places). Single source of the precision rule used both by centimes/2 and by callers validating input up front.