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 services get_file_info.ex
Raw

app/cnabex/cnab240/services/get_file_info.ex

defmodule ExCnab.Cnab240.Services.GetFileInfo do
@moduledoc """
Service to get file infos from filename
"""
import Helpers.ConvertPosition
@spec run(String.t()) :: {:ok, Map.t()}
def run(filename) do
filename
|> String.slice(0..3)
|> String.match?(~r/\d+/)
|> filename_template(filename)
end
defp filename_template(true, filename) do
{:ok,
%{
codigo_convenio: convert_position(filename, 1, 3),
dia_geracao_arquivo: convert_position(filename, 4, 5),
codigo_mes_geracao_arquivo: convert_position(filename, 6),
sequencia_arquivo: convert_position(filename, 7, 8),
nome_arquivo: filename
}}
end
defp filename_template(false, filename) do
{:ok,
%{
codigo_convenio: convert_position(filename, 1, 4),
dia_geracao_arquivo: convert_position(filename, 5, 6),
sequencia_arquivo: convert_position(filename, 7, 8),
nome_arquivo: filename
}}
end
end