nacha 0.1.16 → 0.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/nacha/numeric.rb +1 -1
- data/lib/nacha/record/ack_entry_detail.rb +20 -0
- data/lib/nacha/record/adv_batch_control.rb +18 -0
- data/lib/nacha/record/adv_entry_detail.rb +28 -0
- data/lib/nacha/record/adv_file_control.rb +16 -0
- data/lib/nacha/record/adv_file_header.rb +26 -0
- data/lib/nacha/record/arc_entry_detail.rb +20 -0
- data/lib/nacha/record/base.rb +115 -3
- data/lib/nacha/record/batch_control.rb +22 -0
- data/lib/nacha/record/batch_header.rb +26 -0
- data/lib/nacha/record/boc_entry_detail.rb +20 -0
- data/lib/nacha/record/ccd_addenda.rb +10 -0
- data/lib/nacha/record/ccd_entry_detail.rb +20 -0
- data/lib/nacha/record/cie_addenda.rb +10 -0
- data/lib/nacha/record/cie_entry_detail.rb +20 -0
- data/lib/nacha/record/ctx_addenda.rb +10 -0
- data/lib/nacha/record/ctx_corporate_entry_detail.rb +24 -0
- data/lib/nacha/record/dne_addenda.rb +11 -0
- data/lib/nacha/record/dne_entry_detail.rb +20 -0
- data/lib/nacha/record/enr_addenda.rb +10 -0
- data/lib/nacha/record/enr_entry_detail.rb +24 -0
- data/lib/nacha/record/fifth_iat_addenda.rb +16 -0
- data/lib/nacha/record/file_control.rb +16 -0
- data/lib/nacha/record/file_header.rb +26 -0
- data/lib/nacha/record/filler.rb +4 -0
- data/lib/nacha/record/first_iat_addenda.rb +16 -0
- data/lib/nacha/record/fourth_iat_addenda.rb +16 -0
- data/lib/nacha/record/iat_batch_header.rb +34 -0
- data/lib/nacha/record/iat_entry_detail.rb +24 -0
- data/lib/nacha/record/iat_foreign_coorespondent_bank_information_addenda.rb +18 -0
- data/lib/nacha/record/iat_remittance_information_addenda.rb +10 -0
- data/lib/nacha/record/mte_addenda.rb +24 -0
- data/lib/nacha/record/mte_entry_detail.rb +20 -0
- data/lib/nacha/record/pop_entry_detail.rb +24 -0
- data/lib/nacha/record/pos_addenda.rb +24 -0
- data/lib/nacha/record/pos_entry_detail.rb +20 -0
- data/lib/nacha/record/ppd_addenda.rb +10 -0
- data/lib/nacha/record/ppd_entry_detail.rb +20 -0
- data/lib/nacha/record/rck_entry_detail.rb +20 -0
- data/lib/nacha/record/second_iat_addenda.rb +12 -0
- data/lib/nacha/record/seventh_iat_addenda.rb +13 -1
- data/lib/nacha/record/shr_addenda.rb +24 -0
- data/lib/nacha/record/shr_entry_detail.rb +22 -0
- data/lib/nacha/record/sixth_iat_addenda.rb +12 -0
- data/lib/nacha/record/tel_entry_detail.rb +20 -0
- data/lib/nacha/record/third_iat_addenda.rb +12 -0
- data/lib/nacha/record/trc_entry_detail.rb +22 -0
- data/lib/nacha/record/trx_addenda.rb +10 -0
- data/lib/nacha/record/trx_entry_detail.rb +24 -0
- data/lib/nacha/record/web_addenda.rb +10 -0
- data/lib/nacha/record/web_entry_detail.rb +20 -0
- data/lib/nacha/record/xck_entry_detail.rb +22 -0
- data/lib/nacha/version.rb +1 -1
- data/nacha.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac015c80a2af7bf4ccb82d5d4f61b6989fc97339d245b63f0738504b80098c34
|
4
|
+
data.tar.gz: 6e22d6adb5488eb75bce08eba680ff85b94335a287de3ef5dcbf03084c3f04f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7d60688348901c5182650fd7651c5fc5346eb1b9da3271c6d9a77710646ff74108f2517a6430a8f271930eb592d8a41b52d86e04169cc443da32f54ce6a6e9b
|
7
|
+
data.tar.gz: 628125365a043294bf71d4523c2db3ecb7ad290b1645f2abd8e0ab35339e14e739fd99d89d80a7853c9c0ae165c6fde3864d0ee95b01995d429a56eab54af8d4
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [0.1.17] - 2025-07-25
|
11
|
+
|
12
|
+
- lots of yard documentation for all the Ach record types. Generating
|
13
|
+
documentation so that the AI coders will have something to go by
|
14
|
+
|
10
15
|
## [0.1.16] - 2025-07-22
|
11
16
|
|
12
17
|
- `Nacha::Record::BatchHeader` would blissfully attempt to add a
|
data/lib/nacha/numeric.rb
CHANGED
@@ -41,7 +41,7 @@ class Nacha::Numeric
|
|
41
41
|
@op_value.respond_to?(method_name)
|
42
42
|
end
|
43
43
|
|
44
|
-
#
|
44
|
+
# The value for operations is @op_value. @value may still be a string
|
45
45
|
# from the input data. If an operation is attempted, then @op_value
|
46
46
|
# should be checked to see if the operation is valid for it, not
|
47
47
|
# necessarily the potentially string @value
|
@@ -6,6 +6,26 @@ require 'nacha/record/detail_record_type'
|
|
6
6
|
|
7
7
|
module Nacha
|
8
8
|
module Record
|
9
|
+
# @!attribute [rw] record_type_code
|
10
|
+
# @return [String] Identifies the record as an ACK Entry Detail record with a constant value of '6'.
|
11
|
+
# @!attribute [rw] transaction_code
|
12
|
+
# @return [Nacha::Numeric] Identifies the transaction as an acknowledgment for a received credit entry.
|
13
|
+
# @!attribute [rw] receiving_dfi_identification
|
14
|
+
# @return [Nacha::AbaNumber] The routing number of the financial institution that is to receive the acknowledgement.
|
15
|
+
# @!attribute [rw] dfi_account_number
|
16
|
+
# @return [String] The DFI account number of the receiver from the original entry detail record.
|
17
|
+
# @!attribute [rw] amount
|
18
|
+
# @return [Nacha::Numeric] The amount of the entry being acknowledged, which is always zero for ACK entries.
|
19
|
+
# @!attribute [rw] originl_entry_trace_number
|
20
|
+
# @return [Nacha::Numeric] The trace number from the original Entry Detail Record to which this acknowledgment applies.
|
21
|
+
# @!attribute [rw] receiving_company_name
|
22
|
+
# @return [String] The name of the receiver from the original entry detail record.
|
23
|
+
# @!attribute [rw] discretionary_data
|
24
|
+
# @return [String] Optional data field which can be used by the ODFI or Originator for their own purposes.
|
25
|
+
# @!attribute [rw] addenda_record_indicator
|
26
|
+
# @return [Nacha::Numeric] A code indicating whether an addenda record follows, '1' for yes and '0' for no.
|
27
|
+
# @!attribute [rw] trace_number
|
28
|
+
# @return [Nacha::Numeric] A unique number assigned by the ODFI to this specific acknowledgement entry.
|
9
29
|
class AckEntryDetail < Nacha::Record::Base
|
10
30
|
include DetailRecordType
|
11
31
|
|
@@ -7,6 +7,24 @@ require 'nacha/record/batch_control_record_type'
|
|
7
7
|
module Nacha
|
8
8
|
module Record
|
9
9
|
# The AdvBatchControl record is used to control the batch of adv entry detail records.
|
10
|
+
# @!attribute [rw] record_type_code
|
11
|
+
# @return [String] Identifies the record as an ADV Batch Control record with a constant value of '8'.
|
12
|
+
# @!attribute [rw] service_class_code
|
13
|
+
# @return [Nacha::Numeric] Indicates the type of entries in the batch, such as automated accounting advices.
|
14
|
+
# @!attribute [rw] entry_addenda_count
|
15
|
+
# @return [Nacha::Numeric] A count of all ADV Entry Detail records plus all Addenda records in the batch.
|
16
|
+
# @!attribute [rw] entry_hash
|
17
|
+
# @return [Nacha::Numeric] A hash total of the routing numbers of all ADV Entry Detail records in the batch.
|
18
|
+
# @!attribute [rw] total_debit_entry_dollar_amount
|
19
|
+
# @return [Nacha::Numeric] The total dollar amount of all debit entries in the batch, which is zero for ADV files.
|
20
|
+
# @!attribute [rw] total_credit_entry_dollar_amount
|
21
|
+
# @return [Nacha::Numeric] The total dollar amount of all credit entries in the batch.
|
22
|
+
# @!attribute [rw] ach_operator_data
|
23
|
+
# @return [String] Data that an ACH Operator may use to provide additional information about the batch.
|
24
|
+
# @!attribute [rw] originating_dfi_identification
|
25
|
+
# @return [String] The 8-digit routing number of the ACH Operator that created the batch.
|
26
|
+
# @!attribute [rw] batch_number
|
27
|
+
# @return [Nacha::Numeric] A number assigned by the ACH Operator to uniquely identify the batch.
|
10
28
|
class AdvBatchControl < Nacha::Record::Base
|
11
29
|
include BatchControlRecordType
|
12
30
|
|
@@ -6,6 +6,34 @@ require 'nacha/record/detail_record_type'
|
|
6
6
|
|
7
7
|
module Nacha
|
8
8
|
module Record
|
9
|
+
# @!attribute [rw] record_type_code
|
10
|
+
# @return [String] Identifies the record as an ADV Entry Detail record with a constant value of '6'.
|
11
|
+
# @!attribute [rw] transaction_code
|
12
|
+
# @return [Nacha::Numeric] Identifies the type of transaction, such as a credit or debit.
|
13
|
+
# @!attribute [rw] receiving_dfi_identification
|
14
|
+
# @return [Nacha::AbaNumber] The routing number of the financial institution that is to receive the credit or debit entry.
|
15
|
+
# @!attribute [rw] dfi_account_number
|
16
|
+
# @return [String] The account number at the receiving financial institution to be credited or debited.
|
17
|
+
# @!attribute [rw] amount
|
18
|
+
# @return [Nacha::Numeric] The total dollar amount of the entry.
|
19
|
+
# @!attribute [rw] advice_routing_number
|
20
|
+
# @return [Nacha::Numeric] The routing number of the financial institution responsible for the advice of entry.
|
21
|
+
# @!attribute [rw] file_identification
|
22
|
+
# @return [String] An optional field used by an ACH Operator to uniquely identify the file.
|
23
|
+
# @!attribute [rw] ach_operator_data
|
24
|
+
# @return [String] Optional data used by an ACH Operator.
|
25
|
+
# @!attribute [rw] individual_name
|
26
|
+
# @return [String] The name of the Receiver from the original Entry Detail Record.
|
27
|
+
# @!attribute [rw] discretionary_data
|
28
|
+
# @return [String] Optional data field which can be used by the ODFI or Originator for their own purposes.
|
29
|
+
# @!attribute [rw] addenda_record_indicator
|
30
|
+
# @return [Nacha::Numeric] A code indicating whether an addenda record follows, '1' for yes and '0' for no.
|
31
|
+
# @!attribute [rw] routing_number_of_ach_operator
|
32
|
+
# @return [String] The routing number of the ACH Operator that created the ADV entry.
|
33
|
+
# @!attribute [rw] julian_date_created
|
34
|
+
# @return [Nacha::Numeric] The Julian date on which the ADV entry was created.
|
35
|
+
# @!attribute [rw] sequence_number
|
36
|
+
# @return [Nacha::Numeric] A number assigned by the ACH Operator to uniquely identify the entry within the file.
|
9
37
|
class AdvEntryDetail < Nacha::Record::Base
|
10
38
|
include DetailRecordType
|
11
39
|
|
@@ -6,6 +6,22 @@ require 'nacha/record/file_control_record_type'
|
|
6
6
|
|
7
7
|
module Nacha
|
8
8
|
module Record
|
9
|
+
# @!attribute [rw] record_type_code
|
10
|
+
# @return [String] Identifies the record as an ADV File Control record with a constant value of '9'.
|
11
|
+
# @!attribute [rw] batch_count
|
12
|
+
# @return [Nacha::Numeric] The total number of batch records in the file.
|
13
|
+
# @!attribute [rw] block_count
|
14
|
+
# @return [Nacha::Numeric] The total number of blocks in the file, where a block is 10 lines.
|
15
|
+
# @!attribute [rw] entry_addenda_count
|
16
|
+
# @return [Nacha::Numeric] The total number of entry detail and addenda records in the file.
|
17
|
+
# @!attribute [rw] entry_hash
|
18
|
+
# @return [Nacha::Numeric] The sum of all Entry Hash fields from the Batch Control records in the file.
|
19
|
+
# @!attribute [rw] total_debit_entry_dollar_amount_in_file
|
20
|
+
# @return [Nacha::Numeric] The total value of all debit entries in the file, which is zero for ADV files.
|
21
|
+
# @!attribute [rw] total_credit_entry_dollar_amount_in_file
|
22
|
+
# @return [Nacha::Numeric] The total value of all credit entries in the file.
|
23
|
+
# @!attribute [rw] reserved
|
24
|
+
# @return [String] A reserved field for future use.
|
9
25
|
class AdvFileControl < Nacha::Record::Base
|
10
26
|
include FileControlRecordType
|
11
27
|
|
@@ -6,6 +6,32 @@ require 'nacha/record/file_header_record_type'
|
|
6
6
|
|
7
7
|
module Nacha
|
8
8
|
module Record
|
9
|
+
# @!attribute [rw] record_type_code
|
10
|
+
# @return [String] Identifies the record as an ADV File Header record with a constant value of '1'.
|
11
|
+
# @!attribute [rw] priority_code
|
12
|
+
# @return [Nacha::Numeric] A code that indicates the processing priority of the file.
|
13
|
+
# @!attribute [rw] immediate_destination
|
14
|
+
# @return [Nacha::AbaNumber] The routing number of the ACH Operator or receiving point to which the file is sent.
|
15
|
+
# @!attribute [rw] immediate_origin
|
16
|
+
# @return [Nacha::AbaNumber] The routing number of the ACH Operator that is sending the file.
|
17
|
+
# @!attribute [rw] file_creation_date
|
18
|
+
# @return [String] The date the file was created by the sending institution, in YYMMDD format.
|
19
|
+
# @!attribute [rw] file_creation_time
|
20
|
+
# @return [String] The time the file was created by the sending institution, in HHMM format.
|
21
|
+
# @!attribute [rw] file_id_modifier
|
22
|
+
# @return [String] A code to distinguish between multiple files created on the same date with the same origin and destination.
|
23
|
+
# @!attribute [rw] record_size
|
24
|
+
# @return [String] The number of characters in each record of the file, which is always '094'.
|
25
|
+
# @!attribute [rw] blocking_factor
|
26
|
+
# @return [String] The number of records in a block, which is always '10'.
|
27
|
+
# @!attribute [rw] format_code
|
28
|
+
# @return [String] A code indicating the file format version, which is '1' for current Nacha standards.
|
29
|
+
# @!attribute [rw] immediate_destination_name
|
30
|
+
# @return [String] The name of the ACH Operator or receiving point to which the file is being sent.
|
31
|
+
# @!attribute [rw] immediate_origin_name
|
32
|
+
# @return [String] The name of the ACH Operator that is sending the file.
|
33
|
+
# @!attribute [rw] reference_code
|
34
|
+
# @return [String] A reference code for the file, which is 'ADV FILE' for Automated Accounting Advices.
|
9
35
|
class AdvFileHeader < Nacha::Record::Base
|
10
36
|
include FileHeaderRecordType
|
11
37
|
|
@@ -6,6 +6,26 @@ require 'nacha/record/detail_record_type'
|
|
6
6
|
|
7
7
|
module Nacha
|
8
8
|
module Record
|
9
|
+
# @!attribute [rw] record_type_code
|
10
|
+
# @return [String] Identifies the record as an ARC Entry Detail record with a constant value of '6'.
|
11
|
+
# @!attribute [rw] transaction_code
|
12
|
+
# @return [Nacha::Numeric] Specifies the type of account and the nature of the transaction (e.g., debit to a checking account).
|
13
|
+
# @!attribute [rw] receiving_dfi_identification
|
14
|
+
# @return [Nacha::AbaNumber] The routing number of the financial institution receiving the entry.
|
15
|
+
# @!attribute [rw] dfi_account_number
|
16
|
+
# @return [String] The account number to be debited at the receiving financial institution.
|
17
|
+
# @!attribute [rw] amount
|
18
|
+
# @return [Nacha::Numeric] The total dollar amount of the entry.
|
19
|
+
# @!attribute [rw] check_serial_number
|
20
|
+
# @return [String] The serial number of the source check being converted to an ACH entry.
|
21
|
+
# @!attribute [rw] individual_name
|
22
|
+
# @return [String] The name of the individual to whom the check was issued.
|
23
|
+
# @!attribute [rw] discretionary_data
|
24
|
+
# @return [String] An optional field that can be used by the Originator for their own purposes.
|
25
|
+
# @!attribute [rw] addenda_record_indicator
|
26
|
+
# @return [Nacha::Numeric] Indicates whether an addenda record is present ('1') or not ('0').
|
27
|
+
# @!attribute [rw] trace_number
|
28
|
+
# @return [Nacha::Numeric] A unique number assigned by the ODFI to trace the entry.
|
9
29
|
class ArcEntryDetail < Nacha::Record::Base
|
10
30
|
include DetailRecordType
|
11
31
|
|
data/lib/nacha/record/base.rb
CHANGED
@@ -8,14 +8,29 @@ require 'nacha/record/validations/field_validations'
|
|
8
8
|
module Nacha
|
9
9
|
module Record
|
10
10
|
# Base class for all Nacha records.
|
11
|
+
# @!attribute [r] children
|
12
|
+
# @return [Array<Nacha::Record::Base>] An array of child records associated with this record.
|
13
|
+
# @!attribute [r] original_input_line
|
14
|
+
# @return [String, nil] The original string from the ACH file that this record was parsed from.
|
15
|
+
# @!attribute [r] fields
|
16
|
+
# @return [Hash{Symbol => Nacha::Field}] A hash of field objects that belong to this record, keyed by field name.
|
17
|
+
# @!attribute [rw] parent
|
18
|
+
# @return [Nacha::Record::Base, nil] The parent record of this record in the ACH file hierarchy.
|
19
|
+
# @!attribute [rw] line_number
|
20
|
+
# @return [Integer, nil] The line number of this record within the ACH file.
|
11
21
|
class Base
|
12
22
|
include Validations::FieldValidations
|
13
23
|
|
14
24
|
attr_reader :children, :name, :validations, :original_input_line, :fields
|
25
|
+
|
15
26
|
# :reek:Attribute
|
27
|
+
|
16
28
|
attr_accessor :parent, :line_number
|
17
29
|
|
18
30
|
# :reek:ManualDispatch
|
31
|
+
|
32
|
+
# Initializes a new record object.
|
33
|
+
# @param opts [Hash] A hash of options to set as attributes on the new record.
|
19
34
|
def initialize(opts = {})
|
20
35
|
@children = []
|
21
36
|
@parent = nil
|
@@ -35,6 +50,16 @@ module Nacha
|
|
35
50
|
|
36
51
|
class << self
|
37
52
|
# :reek:LongParameterList, :reek:ManualDispatch
|
53
|
+
# Defines a field for the record type.
|
54
|
+
#
|
55
|
+
# This class method is used in subclasses to declare each field within the NACHA record.
|
56
|
+
# It stores the definition and sets up validations.
|
57
|
+
#
|
58
|
+
# @param name [Symbol] The name of the field.
|
59
|
+
# @param inclusion [String] The inclusion rule for the field ('M' for mandatory, 'R' for required, 'O' for optional).
|
60
|
+
# @param contents [String] The expected content type of the field (e.g., 'Numeric', 'Alphameric', 'C...').
|
61
|
+
# @param position [Range] The character position range of the field in the record string.
|
62
|
+
# @return [void]
|
38
63
|
def nacha_field(name, inclusion:, contents:, position:)
|
39
64
|
Nacha.add_ach_record_type(self)
|
40
65
|
definition[name] = { inclusion: inclusion,
|
@@ -47,14 +72,22 @@ module Nacha
|
|
47
72
|
(validations[name] ||= []) << validation_method
|
48
73
|
end
|
49
74
|
|
75
|
+
# Returns the field definitions for the record class.
|
76
|
+
# @return [Hash] A hash containing the definitions of all fields for this record type.
|
50
77
|
def definition
|
51
78
|
@definition ||= {}
|
52
79
|
end
|
53
80
|
|
81
|
+
# Returns the validation methods for the record class.
|
82
|
+
# @return [Hash] A hash of validation methods for the fields of this record type.
|
54
83
|
def validations
|
55
84
|
@validations ||= {}
|
56
85
|
end
|
57
86
|
|
87
|
+
# Generates and returns a format string for `String#unpack` to parse a record line.
|
88
|
+
#
|
89
|
+
# The format string is built based on the field definitions.
|
90
|
+
# @return [String] The unpack format string.
|
58
91
|
def unpack_str
|
59
92
|
@unpack_str ||= definition.values
|
60
93
|
.sort { |a, b| a[:position].first <=> b[:position].first }
|
@@ -66,6 +99,9 @@ module Nacha
|
|
66
99
|
# :reek:TooManyStatements
|
67
100
|
# rubocop:disable Layout/BlockAlignment,
|
68
101
|
# rubocop:disable Style/StringConcatenation:
|
102
|
+
|
103
|
+
# Generates a Regexp to match against a line to determine if it is of this record type.
|
104
|
+
# @return [Regexp] The regular expression for matching record lines.
|
69
105
|
def matcher
|
70
106
|
@matcher ||= begin
|
71
107
|
output_started = false
|
@@ -99,6 +135,12 @@ module Nacha
|
|
99
135
|
# rubocop:enable Layout/BlockAlignment,
|
100
136
|
# rubocop:enable Style/StringConcatenation:
|
101
137
|
|
138
|
+
# Parses an ACH string and creates a new record instance.
|
139
|
+
#
|
140
|
+
# It unpacks the string based on field definitions, populates the fields,
|
141
|
+
# and runs validations.
|
142
|
+
# @param ach_str [String] The 94-character string representing a NACHA record.
|
143
|
+
# @return [Nacha::Record::Base] A new instance of the record class populated with data from the string.
|
102
144
|
def parse(ach_str)
|
103
145
|
rec = new(original_input_line: ach_str)
|
104
146
|
ach_str.unpack(unpack_str).zip(rec.fields.values) do |input_data, field|
|
@@ -108,12 +150,19 @@ module Nacha
|
|
108
150
|
rec
|
109
151
|
end
|
110
152
|
|
153
|
+
# Returns the record type name.
|
154
|
+
#
|
155
|
+
# The name is derived from the class name, converted to a snake_case symbol.
|
156
|
+
# @return [Symbol] The record type as a symbol (e.g., :file_header).
|
111
157
|
def record_type
|
112
158
|
Nacha.record_name(self)
|
113
159
|
end
|
114
160
|
|
115
|
-
#
|
116
|
-
|
161
|
+
# Returns a hash representation of the record class definition.
|
162
|
+
#
|
163
|
+
# This includes field definitions and child record types.
|
164
|
+
# @return [Hash] A hash representing the structure of the record type.
|
165
|
+
def to_h # :reek:ManualDispatch, :reek:TooManyStatements
|
117
166
|
fields = definition.transform_values do |field_def|
|
118
167
|
{
|
119
168
|
inclusion: field_def[:inclusion],
|
@@ -129,30 +178,52 @@ module Nacha
|
|
129
178
|
{ record_type.to_sym => fields }
|
130
179
|
end
|
131
180
|
|
181
|
+
# Returns a JSON string representing the record class definition.
|
182
|
+
# @param _args [Array] Arguments to be passed to `JSON.pretty_generate`.
|
183
|
+
# @return [String] The JSON representation of the record definition.
|
132
184
|
def to_json(*_args)
|
133
185
|
JSON.pretty_generate(to_h)
|
134
186
|
end
|
135
187
|
end
|
136
188
|
|
137
189
|
# :reek:FeatureEnvy
|
190
|
+
|
191
|
+
# Sets the original input line string for the record.
|
192
|
+
# @param line [String] The original 94-character string from the ACH file.
|
193
|
+
# @return [void]
|
138
194
|
def original_input_line=(line)
|
139
195
|
@original_input_line = line.dup if line.is_a?(String)
|
140
196
|
end
|
141
197
|
|
198
|
+
# Creates field instances from the class's field definitions.
|
199
|
+
#
|
200
|
+
# This method is called during initialization to populate the `@fields` hash.
|
201
|
+
# @return [void]
|
142
202
|
def create_fields_from_definition
|
143
203
|
definition.each_pair do |field_name, field_def|
|
144
204
|
@fields[field_name.to_sym] = Nacha::Field.new(field_def)
|
145
205
|
end
|
146
206
|
end
|
147
207
|
|
208
|
+
# Returns the record type name for the instance.
|
209
|
+
# @return [Symbol] The record type as a symbol.
|
210
|
+
# @see .record_type
|
148
211
|
def record_type
|
149
212
|
self.class.record_type
|
150
213
|
end
|
151
214
|
|
215
|
+
# Returns a human-readable name for the record type.
|
216
|
+
#
|
217
|
+
# It converts the snake_case `record_type` into a capitalized string with spaces.
|
218
|
+
# @return [String] The human-readable name (e.g., 'File Header').
|
152
219
|
def human_name
|
153
220
|
@human_name ||= record_type.to_s.split('_').map(&:capitalize).join(' ')
|
154
221
|
end
|
155
222
|
|
223
|
+
# Returns a hash representation of the record instance.
|
224
|
+
#
|
225
|
+
# The hash includes metadata and a representation of each field's data and errors.
|
226
|
+
# @return [Hash] A hash representing the record's current state.
|
156
227
|
def to_h
|
157
228
|
{ nacha_record_type: record_type,
|
158
229
|
metadata: {
|
@@ -166,16 +237,28 @@ module Nacha
|
|
166
237
|
end)
|
167
238
|
end
|
168
239
|
|
240
|
+
# Returns a JSON string representing the record instance.
|
241
|
+
# @param _args [Array] Arguments to be passed to `JSON.pretty_generate`.
|
242
|
+
# @return [String] The JSON representation of the record's current state.
|
169
243
|
def to_json(*_args)
|
170
244
|
JSON.pretty_generate(to_h)
|
171
245
|
end
|
172
246
|
|
247
|
+
# Generates the 94-character ACH string representation of the record.
|
248
|
+
#
|
249
|
+
# This is done by concatenating the ACH string representation of each field.
|
250
|
+
# @return [String] The 94-character ACH record string.
|
173
251
|
def to_ach
|
174
252
|
@fields.keys.collect do |key|
|
175
253
|
@fields[key].to_ach
|
176
254
|
end.join
|
177
255
|
end
|
178
256
|
|
257
|
+
# Generates an HTML representation of the record.
|
258
|
+
#
|
259
|
+
# This is useful for displaying ACH data in a web interface.
|
260
|
+
# @param _opts [Hash] Options for HTML generation (currently unused).
|
261
|
+
# @return [String] The HTML representation of the record.
|
179
262
|
def to_html(_opts = {})
|
180
263
|
record_error_class = nil
|
181
264
|
|
@@ -191,14 +274,23 @@ module Nacha
|
|
191
274
|
"</div>"
|
192
275
|
end
|
193
276
|
|
277
|
+
# Returns a developer-friendly string representation of the record object.
|
278
|
+
# @return [String] A string showing the class name and a hash representation of the object.
|
194
279
|
def inspect
|
195
280
|
"#<#{self.class.name}> #{to_h}"
|
196
281
|
end
|
197
282
|
|
283
|
+
# Returns the field definitions for the record class.
|
284
|
+
# @return [Hash] A hash containing the definitions of all fields for this record type.
|
285
|
+
# @see .definition
|
198
286
|
def definition
|
199
287
|
self.class.definition
|
200
288
|
end
|
201
289
|
|
290
|
+
# Runs all field-level and record-level validations.
|
291
|
+
#
|
292
|
+
# This method populates the `errors` array on the record and its fields.
|
293
|
+
# @return [void]
|
202
294
|
def validate
|
203
295
|
# Run field-level validations first
|
204
296
|
@fields.each_value(&:validate)
|
@@ -208,7 +300,8 @@ module Nacha
|
|
208
300
|
end
|
209
301
|
end
|
210
302
|
|
211
|
-
#
|
303
|
+
# Checks if the record is valid by running all validations.
|
304
|
+
# @return [Boolean] `true` if the record has no errors, `false` otherwise.
|
212
305
|
def valid?
|
213
306
|
validate
|
214
307
|
errors.empty?
|
@@ -294,15 +387,29 @@ module Nacha
|
|
294
387
|
false
|
295
388
|
end
|
296
389
|
|
390
|
+
# Returns all validation errors for the record and its fields.
|
391
|
+
# @return [Array<String>] An array of error messages.
|
297
392
|
def errors
|
298
393
|
(@errors + @fields.values.map(&:errors)).flatten
|
299
394
|
end
|
300
395
|
|
396
|
+
# Adds a validation error message to the record's error list.
|
397
|
+
# @param err_string [String] The error message to add.
|
398
|
+
# @return [void]
|
301
399
|
def add_error(err_string)
|
302
400
|
@errors << err_string
|
303
401
|
end
|
304
402
|
|
305
403
|
# :reek:TooManyStatements
|
404
|
+
|
405
|
+
# Handles dynamic access to fields as methods.
|
406
|
+
#
|
407
|
+
# This allows getting and setting field data using attribute-style methods
|
408
|
+
# (e.g., `record.amount`, `record.amount = 123.45`).
|
409
|
+
# @param method_name [Symbol] The name of the missing method.
|
410
|
+
# @param args [Array] The arguments passed to the method.
|
411
|
+
# @param block [Proc] A block passed to the method.
|
412
|
+
# @return [Nacha::Field, Object] Returns the `Nacha::Field` object for a getter, or the assigned value for a setter.
|
306
413
|
def method_missing(method_name, *args, &block)
|
307
414
|
method = method_name.to_s
|
308
415
|
field_name = method.gsub(/=$/, '').to_sym
|
@@ -316,6 +423,10 @@ module Nacha
|
|
316
423
|
end
|
317
424
|
end
|
318
425
|
|
426
|
+
# Complements `method_missing` to allow `respond_to?` to work for dynamic field methods.
|
427
|
+
# @param method_name [Symbol] The name of the method to check.
|
428
|
+
# @param _ [Array] Additional arguments (e.g. `include_private`) are ignored.
|
429
|
+
# @return [Boolean] `true` if the method corresponds to a defined field, `false` otherwise.
|
319
430
|
def respond_to_missing?(method_name, *)
|
320
431
|
field_name = method_name.to_s.gsub(/=$/, '').to_sym
|
321
432
|
definition[field_name] || super
|
@@ -331,6 +442,7 @@ module Nacha
|
|
331
442
|
end
|
332
443
|
|
333
444
|
# :reek:TooManyStatements
|
445
|
+
|
334
446
|
def run_record_level_validations_for(field)
|
335
447
|
klass = self.class
|
336
448
|
validations = klass.validations[field]
|
@@ -6,6 +6,28 @@ require 'nacha/record/batch_control_record_type'
|
|
6
6
|
|
7
7
|
module Nacha
|
8
8
|
module Record
|
9
|
+
# @!attribute [rw] record_type_code
|
10
|
+
# @return [String] Identifies the record as a Batch Control record with a constant value of '8'.
|
11
|
+
# @!attribute [rw] service_class_code
|
12
|
+
# @return [Nacha::Numeric] Specifies the type of entries in the batch (e.g., credits, debits, or mixed).
|
13
|
+
# @!attribute [rw] entry_addenda_count
|
14
|
+
# @return [Nacha::Numeric] The total count of entry detail and addenda records within the batch.
|
15
|
+
# @!attribute [rw] entry_hash
|
16
|
+
# @return [Nacha::Numeric] A hash total of the routing numbers of all entry detail records in the batch for validation.
|
17
|
+
# @!attribute [rw] total_debit_entry_dollar_amount
|
18
|
+
# @return [Nacha::Numeric] The total dollar amount of all debit entries in the batch.
|
19
|
+
# @!attribute [rw] total_credit_entry_dollar_amount
|
20
|
+
# @return [Nacha::Numeric] The total dollar amount of all credit entries in the batch.
|
21
|
+
# @!attribute [rw] company_identification
|
22
|
+
# @return [String] The identifier for the company that originated the entries in the batch.
|
23
|
+
# @!attribute [rw] message_authentication_code
|
24
|
+
# @return [String] A code used to authenticate the batch, if required by the ODFI.
|
25
|
+
# @!attribute [rw] reserved
|
26
|
+
# @return [String] A reserved field for future use.
|
27
|
+
# @!attribute [rw] originating_dfi_identification
|
28
|
+
# @return [String] The 8-digit routing number of the financial institution originating the batch.
|
29
|
+
# @!attribute [rw] batch_number
|
30
|
+
# @return [Nacha::Numeric] A number assigned by the ODFI to uniquely identify the batch.
|
9
31
|
class BatchControl < Nacha::Record::Base
|
10
32
|
include BatchControlRecordType
|
11
33
|
|
@@ -5,6 +5,32 @@ require 'nacha/record/batch_header_record_type'
|
|
5
5
|
|
6
6
|
module Nacha
|
7
7
|
module Record
|
8
|
+
# @!attribute [rw] record_type_code
|
9
|
+
# @return [String] Identifies the record as a Batch Header record with a constant value of '5'.
|
10
|
+
# @!attribute [rw] service_class_code
|
11
|
+
# @return [Nacha::Numeric] Defines the type of entries in the batch, such as credits, debits, or mixed.
|
12
|
+
# @!attribute [rw] company_name
|
13
|
+
# @return [String] The name of the company originating the entries in the batch.
|
14
|
+
# @!attribute [rw] company_discretionary_data
|
15
|
+
# @return [String] Optional data field for the Originator's use.
|
16
|
+
# @!attribute [rw] company_identification
|
17
|
+
# @return [String] A unique identifier for the company, typically a tax ID or a DDA number.
|
18
|
+
# @!attribute [rw] standard_entry_class_code
|
19
|
+
# @return [String] A three-letter code (e.g., PPD, CCD) that identifies the payment type.
|
20
|
+
# @!attribute [rw] company_entry_description
|
21
|
+
# @return [String] A description of the purpose of the entries in the batch.
|
22
|
+
# @!attribute [rw] company_descriptive_date
|
23
|
+
# @return [String] A date chosen by the company to describe the entries, such as a payroll date.
|
24
|
+
# @!attribute [rw] effective_entry_date
|
25
|
+
# @return [String] The date on which the entries are intended to be settled.
|
26
|
+
# @!attribute [rw] settlement_date_julian
|
27
|
+
# @return [Nacha::Numeric] A Julian date used by the ACH Operator for settlement, not for use by the Originator.
|
28
|
+
# @!attribute [rw] originator_status_code
|
29
|
+
# @return [String] A code indicating the status of the originator, typically '1' for a financial institution.
|
30
|
+
# @!attribute [rw] originating_dfi_identification
|
31
|
+
# @return [String] The 8-digit routing number of the financial institution originating the batch.
|
32
|
+
# @!attribute [rw] batch_number
|
33
|
+
# @return [Nacha::Numeric] A number assigned by the Originator to uniquely identify the batch.
|
8
34
|
class BatchHeader < Nacha::Record::Base
|
9
35
|
include BatchHeaderRecordType
|
10
36
|
|
@@ -6,6 +6,26 @@ require 'nacha/record/detail_record_type'
|
|
6
6
|
|
7
7
|
module Nacha
|
8
8
|
module Record
|
9
|
+
# @!attribute [rw] record_type_code
|
10
|
+
# @return [String] Identifies the record as a BOC Entry Detail record with a constant value of '6'.
|
11
|
+
# @!attribute [rw] transaction_code
|
12
|
+
# @return [Nacha::Numeric] Specifies the type of account and nature of the transaction.
|
13
|
+
# @!attribute [rw] receiving_dfi_identification
|
14
|
+
# @return [Nacha::AbaNumber] The routing number of the financial institution receiving the entry.
|
15
|
+
# @!attribute [rw] dfi_account_number
|
16
|
+
# @return [String] The account number to be debited at the receiving financial institution.
|
17
|
+
# @!attribute [rw] amount
|
18
|
+
# @return [Nacha::Numeric] The amount of the check being converted to an ACH entry.
|
19
|
+
# @!attribute [rw] check_serial_number
|
20
|
+
# @return [String] The serial number from the source check.
|
21
|
+
# @!attribute [rw] individual_name
|
22
|
+
# @return [String] The name of the person who wrote the check.
|
23
|
+
# @!attribute [rw] discretionary_data
|
24
|
+
# @return [String] Optional field for the Originator's use.
|
25
|
+
# @!attribute [rw] addenda_record_indicator
|
26
|
+
# @return [Nacha::Numeric] Indicates if an addenda record follows.
|
27
|
+
# @!attribute [rw] trace_number
|
28
|
+
# @return [Nacha::Numeric] A unique number assigned by the ODFI for tracing the entry.
|
9
29
|
class BocEntryDetail < Nacha::Record::Base
|
10
30
|
include DetailRecordType
|
11
31
|
|
@@ -6,6 +6,16 @@ require 'nacha/record/addenda_record_type'
|
|
6
6
|
|
7
7
|
module Nacha
|
8
8
|
module Record
|
9
|
+
# @!attribute [rw] record_type_code
|
10
|
+
# @return [String] Identifies the record as an Addenda record with a constant value of '7'.
|
11
|
+
# @!attribute [rw] addenda_type_code
|
12
|
+
# @return [String] Specifies the type of addenda, typically '05' for CCD payment information.
|
13
|
+
# @!attribute [rw] payment_related_information
|
14
|
+
# @return [String] Contains payment-related information, such as an invoice number.
|
15
|
+
# @!attribute [rw] addenda_sequence_number
|
16
|
+
# @return [Nacha::Numeric] The sequence number of this addenda record within the entry.
|
17
|
+
# @!attribute [rw] entry_detail_sequence_number
|
18
|
+
# @return [Nacha::Numeric] The sequence number of the Entry Detail record this addenda is associated with.
|
9
19
|
class CcdAddenda < Nacha::Record::Base
|
10
20
|
include AddendaRecordType
|
11
21
|
|
@@ -6,6 +6,26 @@ require 'nacha/record/detail_record_type'
|
|
6
6
|
|
7
7
|
module Nacha
|
8
8
|
module Record
|
9
|
+
# @!attribute [rw] record_type_code
|
10
|
+
# @return [String] Identifies the record as a CCD Entry Detail record with a constant value of '6'.
|
11
|
+
# @!attribute [rw] transaction_code
|
12
|
+
# @return [Nacha::Numeric] Defines the type of account and transaction (e.g., credit to a checking account).
|
13
|
+
# @!attribute [rw] receiving_dfi_identification
|
14
|
+
# @return [Nacha::AbaNumber] The routing number of the financial institution that will receive the entry.
|
15
|
+
# @!attribute [rw] dfi_account_number
|
16
|
+
# @return [String] The account number at the receiving institution to be credited or debited.
|
17
|
+
# @!attribute [rw] amount
|
18
|
+
# @return [Nacha::Numeric] The transaction amount.
|
19
|
+
# @!attribute [rw] identification_number
|
20
|
+
# @return [String] An identifier for the receiver of the entry.
|
21
|
+
# @!attribute [rw] receiving_company_name
|
22
|
+
# @return [String] The name of the company receiving the payment.
|
23
|
+
# @!attribute [rw] discretionary_data
|
24
|
+
# @return [String] Optional data field for use by the Originator.
|
25
|
+
# @!attribute [rw] addenda_record_indicator
|
26
|
+
# @return [Nacha::Numeric] A flag indicating if an addenda record is included.
|
27
|
+
# @!attribute [rw] trace_number
|
28
|
+
# @return [Nacha::Numeric] A unique number assigned by the ODFI to trace the transaction.
|
9
29
|
class CcdEntryDetail < Nacha::Record::Base
|
10
30
|
include DetailRecordType
|
11
31
|
|
@@ -6,6 +6,16 @@ require 'nacha/record/addenda_record_type'
|
|
6
6
|
|
7
7
|
module Nacha
|
8
8
|
module Record
|
9
|
+
# @!attribute [rw] record_type_code
|
10
|
+
# @return [String] Identifies the record as an Addenda record with a constant value of '7'.
|
11
|
+
# @!attribute [rw] addenda_type_code
|
12
|
+
# @return [String] Specifies the type of addenda, which is '05' for CIE payment-related information.
|
13
|
+
# @!attribute [rw] payment_related_information
|
14
|
+
# @return [String] Contains additional information about the payment, like an invoice number.
|
15
|
+
# @!attribute [rw] addenda_sequence_number
|
16
|
+
# @return [Nacha::Numeric] The sequence number for this addenda record.
|
17
|
+
# @!attribute [rw] entry_detail_sequence_number
|
18
|
+
# @return [Nacha::Numeric] The sequence number of the associated Entry Detail record.
|
9
19
|
class CieAddenda < Nacha::Record::Base
|
10
20
|
include AddendaRecordType
|
11
21
|
|