|
| 1 | +defmodule OnePiece.Nacha.AdvFileHeader do |
| 2 | + import NimbleParsec |
| 3 | + import OnePiece.Nacha.Helpers |
| 4 | + |
| 5 | + @enforce_keys [ |
| 6 | + :record_type_code, |
| 7 | + :priority_code, |
| 8 | + :immediate_destination, |
| 9 | + :immediate_origin, |
| 10 | + :file_creation_date, |
| 11 | + :file_creation_time, |
| 12 | + :file_id_modifier, |
| 13 | + :record_size, |
| 14 | + :blocking_factor, |
| 15 | + :format_code, |
| 16 | + :immediate_destination_name, |
| 17 | + :immediate_origin_name, |
| 18 | + :reference_code, |
| 19 | + :__parsing_info__ |
| 20 | + ] |
| 21 | + |
| 22 | + defstruct @enforce_keys |
| 23 | + |
| 24 | + def post_traverse(rest, parsed_line, context, line, byte_offset) do |
| 25 | + {rest, |
| 26 | + [ |
| 27 | + %__MODULE__{ |
| 28 | + record_type_code: Enum.at(parsed_line, 12), |
| 29 | + priority_code: Enum.at(parsed_line, 11), |
| 30 | + immediate_destination: Enum.at(parsed_line, 10), |
| 31 | + immediate_origin: Enum.at(parsed_line, 9), |
| 32 | + file_creation_date: Enum.at(parsed_line, 8), |
| 33 | + file_creation_time: Enum.at(parsed_line, 7), |
| 34 | + file_id_modifier: Enum.at(parsed_line, 6), |
| 35 | + record_size: Enum.at(parsed_line, 5), |
| 36 | + blocking_factor: Enum.at(parsed_line, 4), |
| 37 | + format_code: Enum.at(parsed_line, 3), |
| 38 | + immediate_destination_name: Enum.at(parsed_line, 2), |
| 39 | + immediate_origin_name: Enum.at(parsed_line, 1), |
| 40 | + reference_code: Enum.at(parsed_line, 0), |
| 41 | + __parsing_info__: OnePiece.Nacha.ParsingInfo.new(line, byte_offset) |
| 42 | + } |
| 43 | + ], context} |
| 44 | + end |
| 45 | + |
| 46 | + def file_header do |
| 47 | + string("1") |
| 48 | + |> label("Record Type Code") |
| 49 | + |> ascii_string([], 2) |
| 50 | + |> label("Priority Code") |
| 51 | + |> ascii_string([], 10) |
| 52 | + |> label("Immediate Destination") |
| 53 | + |> ascii_string([], 10) |
| 54 | + |> label("Immediate Origin") |
| 55 | + |> ascii_string([], 6) |
| 56 | + |> label("File Creation Date") |
| 57 | + |> ascii_string([], 4) |
| 58 | + |> label("File Creation Time") |
| 59 | + |> ascii_string([], 1) |
| 60 | + |> label("File ID Modifier") |
| 61 | + |> ascii_string([], 3) |
| 62 | + |> label("Record Size") |
| 63 | + |> ascii_string([], 2) |
| 64 | + |> label("Blocking Factor") |
| 65 | + |> ascii_string([], 1) |
| 66 | + |> label("Format Code") |
| 67 | + |> ascii_string([], 23) |
| 68 | + |> label("Immediate Destination Name") |
| 69 | + |> ascii_string([], 23) |
| 70 | + |> label("Immediate Origin Name") |
| 71 | + |> ascii_string([], 8) |
| 72 | + |> label("Reference Code") |
| 73 | + |> eol() |
| 74 | + |> post_traverse({__MODULE__, :post_traverse, []}) |
| 75 | + |> unwrap_and_tag(:file_header) |
| 76 | + |> label("ADV File Header") |
| 77 | + end |
| 78 | +end |
0 commit comments