ExCnab240 behaviour (ex_cnab v1.3.6)

Cnab keeps the contexts that define your domain and business logic.

Contexts are also responsible for managing your data, regardless if it comes from the database, an external API or others.

Link to this section Summary

Callbacks

Decode a single file. This will decode the cnab file applying the correct format to each CNAB 240 template

Encode a single file. This will encode your params to a one CNAB file applying the correct format to each CNAB 240 template

Find all details types from a CNAB 240 file The funtion will recieve a map with the cnab 240 file decoded and will return a list with all details types

Link to this section Callbacks

Link to this callback

decode(filepath)

@callback decode(filepath :: String.t()) :: {:ok, Map.t()} | {:error, String.t()}

Decode a single file. This will decode the cnab file applying the correct format to each CNAB 240 template

example

Example

import ExCnab240

decode("JVH1234.rem", %{})
{:ok, %{
  header: %{
    # Content
  },
  details: %{
    # Content
  },
  footer: %{
    # Content
  },
  additional_info: %{
    # Content
  }
}}
Link to this callback

decode(filepath, attrs)

@callback decode(filepath :: String.t(), attrs :: keyword() | map()) ::
  {:ok, Map.t()} | {:error, String.t()}
Link to this callback

decode!(filepath)

@callback decode!(filepath :: String.t()) :: Map.t() | {:error, String.t()}
Link to this callback

decode!(filepath, attrs)

@callback decode!(filepath :: String.t(), attrs :: keyword() | map()) ::
  Map.t() | {:error, String.t()}
@callback encode(params :: Map.t()) ::
  {:ok, %{filename: String.t(), content: String.t()}} | {:error, String.t()}

Encode a single file. This will encode your params to a one CNAB file applying the correct format to each CNAB 240 template

example

Example

import ExCnab240

encode(%{cnab: cnab}, %{filename: "JVH1010101.ret"})
{:ok, %{contnet: "xxx...", filename: "JVH1010101.ret"}}

encode(%{cnab: cnab}, %{})
{:ok, %{contnet: "xxx...", filename: "default.ret"}}

encode!(%{cnab: cnab}, %{filename: "JVH1010101.ret"})
%{contnet: "xxx...", filename: "JVH1010101.ret"}

encode!(%{cnab: cnab}, %{})
%{contnet: "xxx...", filename: "default.ret"}
Link to this callback

encode(params, attrs)

@callback encode(params :: Map.t(), attrs :: keyword() | map()) ::
  {:ok, %{filename: String.t(), content: String.t()}} | {:error, String.t()}
Link to this callback

encode!(params)

@callback encode!(params :: Map.t()) :: %{filename: String.t(), content: String.t()}
Link to this callback

encode!(params, attrs)

@callback encode!(params :: Map.t(), attrs :: keyword() | map()) :: %{
  filename: String.t(),
  content: String.t()
}
Link to this callback

find_details_type(params)

@callback find_details_type(params :: Map.t()) :: any()
@callback find_details_type(params :: Map.t()) ::
  {:ok, %{filename: String.t(), content: String.t()}}
@callback find_details_type(params :: Map.t()) :: any()
@callback find_details_type(params :: Map.t()) :: %{
  filename: String.t(),
  content: String.t()
}

Find all details types from a CNAB 240 file The funtion will recieve a map with the cnab 240 file decoded and will return a list with all details types

example

Example

import ExCnab240

find_details_type(cnab_file)
{:ok, ["A", "B"]}

find_details_type!(cnab_file)
["A", "B"]

Link to this section Functions

Link to this function

decode(filepath, attrs \\ %{})

Link to this function

decode!(filepath, attrs \\ %{})

Link to this function

encode(params, attrs \\ %{})

Link to this function

encode!(params, attrs \\ %{})

Link to this function

find_details_type(params)

Link to this function

find_details_type!(params)