Packages

A CNAB file helper. This library aims to help your bank or cooperative read, decode, display, and perform various operations on a CNAB file. Supported operations: - Read CNAB240 file - Return some data - Get details type

Current section

Files

Jump to
ex_cnab app cnabex cnab240 templates details.ex
Raw

app/cnabex/cnab240/templates/details.ex

defmodule ExCnab.Cnab240.Templates.Details do
@moduledoc """
Module responsible to send the file to the correct template
"""
import Helpers.ConvertPosition
@spec generate(List.t()) :: {:ok, List.t(Map.t())}
def generate(details) do
formated_details =
Enum.map(details, fn register_detail ->
{:ok, detail_object} =
register_detail
|> convert_position(14)
|> payment_template(:generate, register_detail)
detail_object
end)
{:ok, formated_details}
end
@spec encode(List.t()) :: List.t(Map.t())
def encode(details) do
Enum.map(details, fn detail ->
detail.servico.segmento
payment_template(detail.servico.segmento, :encode, detail)
end)
|> Enum.join("\r\n")
end
defp payment_template(type, function, regsiter_detail) do
apply(:"Elixir.ExCnab.Cnab240.Templates.Details.Model#{type}", function, [regsiter_detail])
end
end