CFONB (CFONB v0.1.0)

Copy Markdown View Source

Parser for CFONB bank files (French banking standard, Comité Français d'Organisation et de Normalisation Bancaires).

This first version handles the 120-character account statement (relevé de compte), made of four fixed-width record types:

  • 01 — previous balance (ancien solde)
  • 04 — operation / movement (mouvement)
  • 05 — operation detail (complément), optional and repeatable
  • 07 — new balance (nouveau solde)

See FORMAT.md for the exact field layout, and CFONB.Statement / CFONB.Operation for the returned structs.

Example

{:ok, [statement | _]} = CFONB.parse(File.read!("releve.txt"))
statement.from_balance
#=> #Decimal<-190.40>

Inspired by the Ruby cfonb gem (MIT). Reimplemented from the official CFONB specification, with a compatible data model.

Summary

Functions

Parses the content of a CFONB 120 file into a list of CFONB.Statement.

Same as parse/2 but raises ArgumentError on invalid input.

Parses a standalone operation (04 and its 05 details, without a surrounding statement) into a single CFONB.Operation.

Functions

parse(input, opts \\ [])

@spec parse(
  binary(),
  keyword()
) :: {:ok, [CFONB.Statement.t()]} | {:error, term()}

Parses the content of a CFONB 120 file into a list of CFONB.Statement.

Returns {:ok, statements} or {:error, reason}.

Options

  • :optimistic (default false) — when true, invalid records are skipped instead of aborting, and whatever statements could be built are returned.

parse!(input, opts \\ [])

@spec parse!(
  binary(),
  keyword()
) :: [CFONB.Statement.t()]

Same as parse/2 but raises ArgumentError on invalid input.

parse_operation(input, opts \\ [])

@spec parse_operation(
  binary(),
  keyword()
) :: {:ok, CFONB.Operation.t() | nil} | {:error, term()}

Parses a standalone operation (04 and its 05 details, without a surrounding statement) into a single CFONB.Operation.

Returns {:ok, operation} (or {:ok, nil} if the input has none), or {:error, reason}. Accepts the same :optimistic option as parse/2.

parse_operation!(input, opts \\ [])

@spec parse_operation!(
  binary(),
  keyword()
) :: CFONB.Operation.t() | nil

Same as parse_operation/2 but raises ArgumentError on invalid input.