nacha 0.1.8 → 0.1.12

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.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -3
  3. data/.ruby-version +1 -1
  4. data/CHANGELOG.md +41 -0
  5. data/README.md +1 -1
  6. data/exe/nacha +50 -20
  7. data/lib/nacha/aba_number.rb +17 -14
  8. data/lib/nacha/ach_date.rb +15 -8
  9. data/lib/nacha/field.rb +69 -58
  10. data/lib/nacha/has_errors.rb +12 -8
  11. data/lib/nacha/numeric.rb +13 -10
  12. data/lib/nacha/parser.rb +33 -16
  13. data/lib/nacha/parser_context.rb +4 -9
  14. data/lib/nacha/record/ack_entry_detail.rb +15 -8
  15. data/lib/nacha/record/adv_batch_control.rb +13 -6
  16. data/lib/nacha/record/adv_entry_detail.rb +3 -2
  17. data/lib/nacha/record/adv_file_control.rb +10 -9
  18. data/lib/nacha/record/adv_file_header.rb +12 -7
  19. data/lib/nacha/record/arc_entry_detail.rb +2 -2
  20. data/lib/nacha/record/base.rb +128 -108
  21. data/lib/nacha/record/batch_control.rb +13 -7
  22. data/lib/nacha/record/batch_header.rb +20 -11
  23. data/lib/nacha/record/batch_header_record_type.rb +1 -1
  24. data/lib/nacha/record/boc_entry_detail.rb +3 -2
  25. data/lib/nacha/record/ccd_addenda.rb +2 -2
  26. data/lib/nacha/record/ccd_entry_detail.rb +3 -2
  27. data/lib/nacha/record/cie_addenda.rb +2 -2
  28. data/lib/nacha/record/cie_entry_detail.rb +5 -3
  29. data/lib/nacha/record/ctx_addenda.rb +2 -2
  30. data/lib/nacha/record/ctx_corporate_entry_detail.rb +2 -2
  31. data/lib/nacha/record/dne_addenda.rb +2 -2
  32. data/lib/nacha/record/dne_entry_detail.rb +6 -4
  33. data/lib/nacha/record/enr_addenda.rb +3 -2
  34. data/lib/nacha/record/enr_entry_detail.rb +4 -3
  35. data/lib/nacha/record/fifth_iat_addenda.rb +8 -4
  36. data/lib/nacha/record/file_control.rb +9 -5
  37. data/lib/nacha/record/file_control_record_type.rb +1 -1
  38. data/lib/nacha/record/file_header.rb +13 -7
  39. data/lib/nacha/record/file_header_record_type.rb +1 -1
  40. data/lib/nacha/record/filler.rb +3 -3
  41. data/lib/nacha/record/filler_record_type.rb +3 -1
  42. data/lib/nacha/record/first_iat_addenda.rb +3 -2
  43. data/lib/nacha/record/fourth_iat_addenda.rb +7 -4
  44. data/lib/nacha/record/iat_batch_header.rb +5 -3
  45. data/lib/nacha/record/iat_entry_detail.rb +7 -4
  46. data/lib/nacha/record/iat_foreign_coorespondent_bank_information_addenda.rb +10 -6
  47. data/lib/nacha/record/iat_remittance_information_addenda.rb +3 -2
  48. data/lib/nacha/record/mte_addenda.rb +4 -3
  49. data/lib/nacha/record/mte_entry_detail.rb +5 -3
  50. data/lib/nacha/record/pop_entry_detail.rb +3 -2
  51. data/lib/nacha/record/pos_addenda.rb +6 -3
  52. data/lib/nacha/record/pos_entry_detail.rb +5 -3
  53. data/lib/nacha/record/ppd_addenda.rb +3 -2
  54. data/lib/nacha/record/ppd_entry_detail.rb +5 -3
  55. data/lib/nacha/record/rck_entry_detail.rb +3 -2
  56. data/lib/nacha/record/second_iat_addenda.rb +3 -2
  57. data/lib/nacha/record/seventh_iat_addenda.rb +3 -2
  58. data/lib/nacha/record/shr_addenda.rb +5 -3
  59. data/lib/nacha/record/shr_entry_detail.rb +3 -2
  60. data/lib/nacha/record/sixth_iat_addenda.rb +5 -3
  61. data/lib/nacha/record/tel_entry_detail.rb +5 -3
  62. data/lib/nacha/record/third_iat_addenda.rb +3 -2
  63. data/lib/nacha/record/trc_entry_detail.rb +3 -2
  64. data/lib/nacha/record/trx_addenda.rb +3 -2
  65. data/lib/nacha/record/trx_entry_detail.rb +5 -3
  66. data/lib/nacha/record/validations/field_validations.rb +26 -14
  67. data/lib/nacha/record/validations/record_validations.rb +2 -1
  68. data/lib/nacha/record/web_addenda.rb +3 -2
  69. data/lib/nacha/record/web_entry_detail.rb +5 -3
  70. data/lib/nacha/record/xck_entry_detail.rb +3 -2
  71. data/lib/nacha/version.rb +4 -1
  72. data/lib/nacha.rb +84 -20
  73. data/nacha.gemspec +13 -10
  74. metadata +38 -21
@@ -1,11 +1,12 @@
1
1
  # coding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'nacha/record/base.rb'
5
- require 'nacha/record/detail_record_type.rb'
4
+ require 'nacha/record/base'
5
+ require 'nacha/record/detail_record_type'
6
6
 
7
7
  module Nacha
8
8
  module Record
9
+ # Represents a Point-of-Purchase (POP) entry detail record.
9
10
  class PopEntryDetail < Nacha::Record::Base
10
11
  include DetailRecordType
11
12
 
@@ -1,13 +1,15 @@
1
1
  # coding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'nacha/record/base.rb'
5
- require 'nacha/record/addenda_record_type.rb'
4
+ require 'nacha/record/base'
5
+ require 'nacha/record/addenda_record_type'
6
6
 
7
7
  module Nacha
8
8
  module Record
9
+ # Represents a Point-of-Sale (POS) addenda record.
9
10
  class PosAddenda < Nacha::Record::Base
10
11
  include AddendaRecordType
12
+
11
13
  nacha_field :record_type_code, inclusion: 'M', contents: 'C7', position: 1..1
12
14
  nacha_field :addenda_type_code, inclusion: 'M', contents: 'C02', position: 2..3
13
15
  nacha_field :reference_information_1, inclusion: 'O', contents: 'Alphameric', position: 4..10
@@ -15,7 +17,8 @@ module Nacha
15
17
  nacha_field :terminal_identification_code, inclusion: 'R', contents: 'Alphameric', position: 14..19
16
18
  nacha_field :transaction_serial_number, inclusion: 'R', contents: 'Alphameric', position: 20..25
17
19
  nacha_field :transaction_date, inclusion: 'O', contents: 'Alphameric', position: 26..29
18
- nacha_field :authorization_code_or_card_expiration_date, inclusion: 'O', contents: 'Alphameric', position: 30..35
20
+ nacha_field :authorization_code_or_card_expiration_date, inclusion: 'O', contents: 'Alphameric',
21
+ position: 30..35
19
22
  nacha_field :terminal_location, inclusion: 'R', contents: 'Alphameric', position: 36..62
20
23
  nacha_field :terminal_city, inclusion: 'R', contents: 'Alphameric', position: 63..77
21
24
  nacha_field :terminal_state, inclusion: 'M', contents: 'Numeric', position: 78..79
@@ -1,11 +1,12 @@
1
1
  # coding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'nacha/record/base.rb'
5
- require 'nacha/record/detail_record_type.rb'
4
+ require 'nacha/record/base'
5
+ require 'nacha/record/detail_record_type'
6
6
 
7
7
  module Nacha
8
8
  module Record
9
+ # Represents a Point-of-Sale (POS) entry detail record.
9
10
  class PosEntryDetail < Nacha::Record::Base
10
11
  include DetailRecordType
11
12
 
@@ -14,7 +15,8 @@ module Nacha
14
15
  nacha_field :receiving_dfi_identification, inclusion: 'M', contents: 'TTTTAAAAC', position: 4..12
15
16
  nacha_field :dfi_account_number, inclusion: 'R', contents: 'Alphameric', position: 13..29
16
17
  nacha_field :amount, inclusion: 'M', contents: '$$$$$$$$¢¢', position: 30..39
17
- nacha_field :individual_identification_number, inclusion: 'O', contents: 'Alphameric', position: 40..54
18
+ nacha_field :individual_identification_number, inclusion: 'O', contents: 'Alphameric',
19
+ position: 40..54
18
20
  nacha_field :individual_name, inclusion: 'R', contents: 'Alphameric', position: 55..76
19
21
  nacha_field :card_transaction_type_code, inclusion: 'M', contents: 'Alphameric', position: 77..78
20
22
  nacha_field :addenda_record_indicator, inclusion: 'M', contents: 'Numeric', position: 79..79
@@ -1,11 +1,12 @@
1
1
  # coding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'nacha/record/base.rb'
5
- require 'nacha/record/addenda_record_type.rb'
4
+ require 'nacha/record/base'
5
+ require 'nacha/record/addenda_record_type'
6
6
 
7
7
  module Nacha
8
8
  module Record
9
+ # Represents a Prearranged Payment and Deposit (PPD) addenda record.
9
10
  class PpdAddenda < Nacha::Record::Base
10
11
  include AddendaRecordType
11
12
 
@@ -1,11 +1,12 @@
1
1
  # coding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'nacha/record/base.rb'
5
- require 'nacha/record/detail_record_type.rb'
4
+ require 'nacha/record/base'
5
+ require 'nacha/record/detail_record_type'
6
6
 
7
7
  module Nacha
8
8
  module Record
9
+ # Describes a PPD (Prearranged Payment and Deposit) Entry Detail record.
9
10
  class PpdEntryDetail < Nacha::Record::Base
10
11
  include DetailRecordType
11
12
 
@@ -14,7 +15,8 @@ module Nacha
14
15
  nacha_field :receiving_dfi_identification, inclusion: 'M', contents: 'TTTTAAAAC', position: 4..12
15
16
  nacha_field :dfi_account_number, inclusion: 'R', contents: 'Alphameric', position: 13..29
16
17
  nacha_field :amount, inclusion: 'M', contents: '$$$$$$$$¢¢', position: 30..39
17
- nacha_field :individual_identification_number, inclusion: 'O', contents: 'Alphameric', position: 40..54
18
+ nacha_field :individual_identification_number, inclusion: 'O', contents: 'Alphameric',
19
+ position: 40..54
18
20
  nacha_field :individual_name, inclusion: 'R', contents: 'Alphameric', position: 55..76
19
21
  nacha_field :discretionary_data, inclusion: 'O', contents: 'Alphameric', position: 77..78
20
22
  nacha_field :addenda_record_indicator, inclusion: 'M', contents: 'Numeric', position: 79..79
@@ -1,11 +1,12 @@
1
1
  # coding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'nacha/record/base.rb'
5
- require 'nacha/record/detail_record_type.rb'
4
+ require 'nacha/record/base'
5
+ require 'nacha/record/detail_record_type'
6
6
 
7
7
  module Nacha
8
8
  module Record
9
+ # Represents a Re-presented Check Entry (RCK) detail record.
9
10
  class RckEntryDetail < Nacha::Record::Base
10
11
  include DetailRecordType
11
12
 
@@ -1,11 +1,12 @@
1
1
  # coding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'nacha/record/base.rb'
5
- require 'nacha/record/addenda_record_type.rb'
4
+ require 'nacha/record/base'
5
+ require 'nacha/record/addenda_record_type'
6
6
 
7
7
  module Nacha
8
8
  module Record
9
+ # Represents a second IAT addenda record
9
10
  class SecondIatAddenda < Nacha::Record::Base
10
11
  include AddendaRecordType
11
12
 
@@ -1,11 +1,12 @@
1
1
  # coding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'nacha/record/base.rb'
5
- require 'nacha/record/addenda_record_type.rb'
4
+ require 'nacha/record/base'
5
+ require 'nacha/record/addenda_record_type'
6
6
 
7
7
  module Nacha
8
8
  module Record
9
+ # Represents a seventh IAT addenda record.
9
10
  class SeventhIatAddenda < Nacha::Record::Base
10
11
  include AddendaRecordType
11
12
 
@@ -1,11 +1,12 @@
1
1
  # coding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'nacha/record/base.rb'
5
- require 'nacha/record/addenda_record_type.rb'
4
+ require 'nacha/record/base'
5
+ require 'nacha/record/addenda_record_type'
6
6
 
7
7
  module Nacha
8
8
  module Record
9
+ # Represents a Shared Network Entry (SHR) addenda record.
9
10
  class ShrAddenda < Nacha::Record::Base
10
11
  include AddendaRecordType
11
12
 
@@ -16,7 +17,8 @@ module Nacha
16
17
  nacha_field :terminal_identification_code, inclusion: 'R', contents: 'Alphameric', position: 14..19
17
18
  nacha_field :transaction_serial_number, inclusion: 'R', contents: 'Alphameric', position: 20..25
18
19
  nacha_field :transaction_date, inclusion: 'O', contents: 'Alphameric', position: 26..29
19
- nacha_field :authorization_code_or_card_expiration_date, inclusion: 'O', contents: 'Alphameric', position: 30..35
20
+ nacha_field :authorization_code_or_card_expiration_date, inclusion: 'O', contents: 'Alphameric',
21
+ position: 30..35
20
22
  nacha_field :terminal_location, inclusion: 'R', contents: 'Alphameric', position: 36..62
21
23
  nacha_field :terminal_city, inclusion: 'R', contents: 'Alphameric', position: 63..77
22
24
  nacha_field :terminal_state, inclusion: 'M', contents: 'Numeric', position: 78..79
@@ -1,11 +1,12 @@
1
1
  # coding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'nacha/record/base.rb'
5
- require 'nacha/record/detail_record_type.rb'
4
+ require 'nacha/record/base'
5
+ require 'nacha/record/detail_record_type'
6
6
 
7
7
  module Nacha
8
8
  module Record
9
+ # Represents a Shared Network Entry (SHR) detail record.
9
10
  class ShrEntryDetail < Nacha::Record::Base
10
11
  include DetailRecordType
11
12
 
@@ -1,11 +1,12 @@
1
1
  # coding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'nacha/record/base.rb'
5
- require 'nacha/record/addenda_record_type.rb'
4
+ require 'nacha/record/base'
5
+ require 'nacha/record/addenda_record_type'
6
6
 
7
7
  module Nacha
8
8
  module Record
9
+ # Represents a sixth IAT addenda record
9
10
  class SixthIatAddenda < Nacha::Record::Base
10
11
  include AddendaRecordType
11
12
 
@@ -13,7 +14,8 @@ module Nacha
13
14
  nacha_field :addenda_type_code, inclusion: 'M', contents: 'C15', position: 2..3
14
15
  nacha_field :receiver_identification_number, inclusion: 'O', contents: 'Alphameric', position: 4..18
15
16
  nacha_field :receiver_street_address, inclusion: 'M', contents: 'Alphameric', position: 19..53
16
- nacha_field :reserved, inclusion: 'M', contents: 'C ', position: 54..87
17
+ nacha_field :reserved, inclusion: 'M', contents: 'C ',
18
+ position: 54..87
17
19
  nacha_field :entry_detail_sequence_number, inclusion: 'M', contents: 'Numeric', position: 88..94
18
20
  end
19
21
  end
@@ -1,11 +1,12 @@
1
1
  # coding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'nacha/record/base.rb'
5
- require 'nacha/record/detail_record_type.rb'
4
+ require 'nacha/record/base'
5
+ require 'nacha/record/detail_record_type'
6
6
 
7
7
  module Nacha
8
8
  module Record
9
+ # Represents a Telephone-Initiated Entry (TEL) detail record.
9
10
  class TelEntryDetail < Nacha::Record::Base
10
11
  include DetailRecordType
11
12
 
@@ -14,7 +15,8 @@ module Nacha
14
15
  nacha_field :receiving_dfi_identification, inclusion: 'M', contents: 'TTTTAAAAC', position: 4..12
15
16
  nacha_field :dfi_account_number, inclusion: 'R', contents: 'Alphameric', position: 13..29
16
17
  nacha_field :amount, inclusion: 'M', contents: '$$$$$$$$¢¢', position: 30..39
17
- nacha_field :individual_identification_number, inclusion: 'O', contents: 'Alphameric', position: 40..54
18
+ nacha_field :individual_identification_number, inclusion: 'O', contents: 'Alphameric',
19
+ position: 40..54
18
20
  nacha_field :individual_name, inclusion: 'M', contents: 'Alphameric', position: 55..76
19
21
  nacha_field :payment_type_code, inclusion: 'O', contents: 'Alphameric', position: 77..78
20
22
  nacha_field :addenda_record_indicator, inclusion: 'M', contents: 'Numeric', position: 79..79
@@ -1,11 +1,12 @@
1
1
  # coding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'nacha/record/base.rb'
5
- require 'nacha/record/addenda_record_type.rb'
4
+ require 'nacha/record/base'
5
+ require 'nacha/record/addenda_record_type'
6
6
 
7
7
  module Nacha
8
8
  module Record
9
+ # Represents a third IAT addenda record.
9
10
  class ThirdIatAddenda < Nacha::Record::Base
10
11
  include AddendaRecordType
11
12
 
@@ -1,11 +1,12 @@
1
1
  # coding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'nacha/record/base.rb'
5
- require 'nacha/record/detail_record_type.rb'
4
+ require 'nacha/record/base'
5
+ require 'nacha/record/detail_record_type'
6
6
 
7
7
  module Nacha
8
8
  module Record
9
+ # Represents a Truncated Entry (TRC) detail record.
9
10
  class TrcEntryDetail < Nacha::Record::Base
10
11
  include DetailRecordType
11
12
 
@@ -1,11 +1,12 @@
1
1
  # coding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'nacha/record/base.rb'
5
- require 'nacha/record/addenda_record_type.rb'
4
+ require 'nacha/record/base'
5
+ require 'nacha/record/addenda_record_type'
6
6
 
7
7
  module Nacha
8
8
  module Record
9
+ # Represents a Truncated Entry (TRX) addenda record.
9
10
  class TrxAddenda < Nacha::Record::Base
10
11
  include AddendaRecordType
11
12
 
@@ -1,11 +1,12 @@
1
1
  # coding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'nacha/record/base.rb'
5
- require 'nacha/record/detail_record_type.rb'
4
+ require 'nacha/record/base'
5
+ require 'nacha/record/detail_record_type'
6
6
 
7
7
  module Nacha
8
8
  module Record
9
+ # Represents a Truncated Entry with Remittance Data (TRX) detail record.
9
10
  class TrxEntryDetail < Nacha::Record::Base
10
11
  include DetailRecordType
11
12
 
@@ -16,7 +17,8 @@ module Nacha
16
17
  nacha_field :total_amount, inclusion: 'M', contents: '$$$$$$$$¢¢', position: 30..39
17
18
  nacha_field :identification_number, inclusion: 'O', contents: 'Alphameric', position: 40..54
18
19
  nacha_field :number_of_addenda_records, inclusion: 'M', contents: 'Numeric', position: 55..58
19
- nacha_field :receiving_company_name_id_number, inclusion: 'R', contents: 'Alphameric', position: 59..74
20
+ nacha_field :receiving_company_name_id_number, inclusion: 'R', contents: 'Alphameric',
21
+ position: 59..74
20
22
  nacha_field :reserved, inclusion: 'M', contents: 'C ', position: 75..76
21
23
  nacha_field :item_type_indicator, inclusion: 'O', contents: 'Alphameric', position: 77..78
22
24
  nacha_field :addenda_record_indicator, inclusion: 'M', contents: 'Numeric', position: 79..79
@@ -5,37 +5,49 @@ module Nacha
5
5
  module Record
6
6
  module Validations
7
7
  module FieldValidations
8
- def self.included base
8
+ def self.included(base)
9
9
  base.extend ClassMethods
10
10
  end
11
+
11
12
  module ClassMethods
12
- def check_field_error(field, message = nil, condition = nil)
13
- (block_given? ? yield : condition) || (field.add_error("'#{field.name}' '#{field}' is invalid") && false)
13
+ def check_field_error(field, _message = nil, condition = nil)
14
+ (block_given? ? yield : condition) ||
15
+ (field.add_error("'#{field.name}' '#{field}' is invalid") && false)
14
16
  end
15
17
 
16
- def valid_service_class_code field
17
- check_field_error(field, "'#{field.name}' '#{field}' should be one of #{SERVICE_CLASS_CODES.join(', ')}") {
18
+ def valid_service_class_code(field)
19
+ check_field_error(
20
+ field,
21
+ "'#{field.name}' '#{field}' should be one of #{SERVICE_CLASS_CODES.join(', ')}"
22
+ ) do
18
23
  SERVICE_CLASS_CODES.include? field.to_s
19
- }
24
+ end
20
25
  end
21
26
 
22
- def valid_standard_entry_class_code field
23
- check_field_error(field, "'#{field.name}' '#{field}' should be one of #{STANDARD_ENTRY_CLASS_CODES.join(', ')}") {
27
+ def valid_standard_entry_class_code(field)
28
+ check_field_error(
29
+ field,
30
+ "'#{field.name}' '#{field}' should be one of " \
31
+ "#{STANDARD_ENTRY_CLASS_CODES.join(', ')}"
32
+ ) do
24
33
  STANDARD_ENTRY_CLASS_CODES.include? field.data
25
- }
34
+ end
26
35
  end
27
36
 
28
- def valid_transaction_code field
29
- check_field_error(field, "'#{field.name}' '#{field}' should be one of #{TRANSACTION_CODES.join(', ')}") {
37
+ def valid_transaction_code(field)
38
+ check_field_error(
39
+ field,
40
+ "'#{field.name}' '#{field}' should be one of #{TRANSACTION_CODES.join(', ')}"
41
+ ) do
30
42
  TRANSACTION_CODES.include? field.to_s
31
- }
43
+ end
32
44
  end
33
45
 
34
- def valid_receiving_dfi_identification field
46
+ def valid_receiving_dfi_identification(field)
35
47
  check_field_error(field) { field.valid? }
36
48
  end
37
49
 
38
- def valid_filler field
50
+ def valid_filler(field)
39
51
  check_field_error(field) { field.to_s == ('9' * 93) }
40
52
  end
41
53
  end
@@ -5,9 +5,10 @@ module Nacha
5
5
  module Record
6
6
  module Validations
7
7
  module RecordValidations
8
- def self.included base
8
+ def self.included(base)
9
9
  base.extend ClassMethods
10
10
  end
11
+
11
12
  module ClassMethods
12
13
  end
13
14
  end
@@ -1,11 +1,12 @@
1
1
  # coding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'nacha/record/base.rb'
5
- require 'nacha/record/addenda_record_type.rb'
4
+ require 'nacha/record/base'
5
+ require 'nacha/record/addenda_record_type'
6
6
 
7
7
  module Nacha
8
8
  module Record
9
+ # Represents an Internet-Initiated Entry (WEB) addenda record.
9
10
  class WebAddenda < Nacha::Record::Base
10
11
  include AddendaRecordType
11
12
 
@@ -1,11 +1,12 @@
1
1
  # coding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'nacha/record/base.rb'
5
- require 'nacha/record/detail_record_type.rb'
4
+ require 'nacha/record/base'
5
+ require 'nacha/record/detail_record_type'
6
6
 
7
7
  module Nacha
8
8
  module Record
9
+ # Represents an Internet-Initiated Entry (WEB) detail record.
9
10
  class WebEntryDetail < Nacha::Record::Base
10
11
  include DetailRecordType
11
12
 
@@ -14,7 +15,8 @@ module Nacha
14
15
  nacha_field :receiving_dfi_identification, inclusion: 'M', contents: 'TTTTAAAAC', position: 4..12
15
16
  nacha_field :dfi_account_number, inclusion: 'R', contents: 'Alphameric', position: 13..29
16
17
  nacha_field :amount, inclusion: 'M', contents: '$$$$$$$$¢¢', position: 30..39
17
- nacha_field :individual_identification_number, inclusion: 'O', contents: 'Alphameric', position: 40..54
18
+ nacha_field :individual_identification_number, inclusion: 'O', contents: 'Alphameric',
19
+ position: 40..54
18
20
  nacha_field :individual_name, inclusion: 'R', contents: 'Alphameric', position: 55..76
19
21
  nacha_field :payment_type_code, inclusion: 'O', contents: 'Alphameric', position: 77..78
20
22
  nacha_field :addenda_record_indicator, inclusion: 'M', contents: 'Numeric', position: 79..79
@@ -1,11 +1,12 @@
1
1
  # coding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'nacha/record/base.rb'
5
- require 'nacha/record/detail_record_type.rb'
4
+ require 'nacha/record/base'
5
+ require 'nacha/record/detail_record_type'
6
6
 
7
7
  module Nacha
8
8
  module Record
9
+ # Represents a Destroyed Check Entry (XCK) detail record.
9
10
  class XckEntryDetail < Nacha::Record::Base
10
11
  include DetailRecordType
11
12
 
data/lib/nacha/version.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Nacha
4
- VERSION = '0.1.8'
4
+ module Version
5
+ STRING = '0.1.12'
6
+ end
7
+ VERSION = Version::STRING
5
8
  end
data/lib/nacha.rb CHANGED
@@ -1,5 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Uncomment to use debugger
4
+ # if RUBY_ENGINE == 'ruby'
5
+ # require "byebug"
6
+ # end
7
+ #
8
+ # if RUBY_ENGINE == 'jruby'
9
+ # require "pry-nav"
10
+ # end
11
+
3
12
  require 'yaml'
4
13
  require 'nacha/version'
5
14
  require 'nacha/aba_number'
@@ -7,30 +16,61 @@ require 'nacha/ach_date'
7
16
  require 'nacha/field'
8
17
  require 'nacha/numeric'
9
18
 
19
+ # Nacha is a Ruby gem for parsing, validating, and generating NACHA
20
+ # (National Automated Clearing House Association) files.
21
+ # It provides a structured way to work with ACH (Automated Clearing House) records,
22
+ # including various entry detail, addenda, batch, and file control records.
10
23
  module Nacha
11
24
  STANDARD_ENTRY_CLASS_CODES = %w[ACK ADV ARC ATX BOC CCD PPD CIE
12
- COR CTX DNE ENR IAT POP POS SHR
13
- MTE RCK TEL TRC TRX WEB XCK].freeze
25
+ COR CTX DNE ENR IAT POP POS SHR
26
+ MTE RCK TEL TRC TRX WEB XCK].freeze
14
27
 
15
28
  SERVICE_CLASS_CODES = %w[200 220 225 280].freeze
16
29
 
17
30
  CREDIT_TRANSACTION_CODES = %w[20 21 22 23 24 30 31 32 33 34 41 42
18
- 43 44 51 52 53 54 81 83 85 87].freeze
31
+ 43 44 51 52 53 54 81 83 85 87].freeze
19
32
  DEBIT_TRANSACTION_CODES = %w[25 26 27 28 29 35 36 37 38 39 46 47
20
- 48 49 55 56 82 84 86 88].freeze
33
+ 48 49 55 56 82 84 86 88].freeze
21
34
 
22
35
  TRANSACTION_CODES = (CREDIT_TRANSACTION_CODES + DEBIT_TRANSACTION_CODES).freeze
23
- @@ach_record_types = []
24
36
 
25
- def self.add_ach_record_type(klass)
26
- @@ach_record_types << klass unless @@ach_record_types.include?(klass)
27
- end
37
+ class << self
38
+ # Adds a new ACH record type class to the list of defined record types.
39
+ # This is used internally by the parser to determine which record classes
40
+ # are available for parsing a NACHA file. As the `nacha_field` method is
41
+ # executed for each of the record types, these record types are added to
42
+ # the Nacha module's class variable `@@ach_record_types`.
43
+ #
44
+ # @param klass [Class, String] The record class or its name (as a String) to add.
45
+ # @return [void]
46
+ def add_ach_record_type(klass)
47
+ return unless klass
28
48
 
29
- def self.ach_record_types
30
- @@ach_record_types
31
- end
49
+ klass = klass.to_s
50
+ @ach_record_types ||= []
51
+ @ach_record_types << klass unless @ach_record_types.include?(klass)
52
+ end
32
53
 
33
- class << self
54
+ # Returns an array of all currently registered ACH record type class names.
55
+ #
56
+ # @return [Array<String>] An array of ACH record class names.
57
+ def ach_record_types
58
+ @ach_record_types || []
59
+ end
60
+
61
+ def to_h
62
+ types_hash = {}
63
+ ach_record_types.each do |record_type|
64
+ types_hash.merge! Object.const_get(record_type).to_h
65
+ end
66
+ types_hash
67
+ end
68
+
69
+ # Parses a NACHA file or string into a structured object representation.
70
+ #
71
+ # @param object [String, File, IO] The input to parse, either a string containing
72
+ # NACHA data or an IO object (e.g., a File) representing the NACHA file.
73
+ # @return [Nacha::Record::Base] The parsed NACHA file object.
34
74
  def parse(object)
35
75
  parser = Nacha::Parser.new
36
76
  if object.is_a?(String)
@@ -40,27 +80,51 @@ module Nacha
40
80
  end
41
81
  end
42
82
 
83
+ # Converts a given string into a underscored, lowercase record name.
84
+ # This is typically used to derive a human-readable or programmatic
85
+ # name from a class name or similar string.
86
+ #
87
+ # @param str [String] The string to convert.
88
+ # @return [String] The underscored and lowercased record name.
43
89
  def record_name(str)
44
90
  underscore(str.to_s).split('/').last
45
91
  end
46
92
 
93
+ # Converts a camel-cased string to its underscore equivalent.
94
+ # This method handles module namespaces (::) by converting them to slashes.
95
+ #
96
+ # @param str [String] The string to underscore.
97
+ # @return [String] The underscored string.
47
98
  def underscore(str)
48
- str.gsub(/::/, '/').
49
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
50
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
51
- tr('-', '_').
52
- downcase
99
+ str.gsub(/::/, '/')
100
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
101
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
102
+ .tr('-', '_')
103
+ .downcase
53
104
  end
54
105
  end
55
106
  end
56
107
 
57
- Gem.find_files('nacha/record/*.rb').reject{|f| f =~ /\/spec\//}.each do |file|
108
+ # Load all record types from nacha/record/*.rb and nacha/record/**/*.rb
109
+ # This will ensure that all record classes are loaded before the parser is used
110
+
111
+ require 'nacha/record/base'
112
+ require 'nacha/record/file_header_record_type'
113
+ require 'nacha/record/file_control_record_type'
114
+ require 'nacha/record/detail_record_type'
115
+
116
+ # Ensure that the record types are loaded before the parser is used
117
+ # This is necessary because the parser relies on the record types being defined
118
+ # and available in the Nacha module.
119
+
120
+ Gem.find_files('nacha/record/*.rb').reject { |f| f.include?('/spec/') }.each do |file|
58
121
  require File.expand_path(file)
59
122
  end
60
123
 
61
- Gem.find_files('nacha/record/**/*.rb').reject{|f| f =~ /\/spec\//}.each do |file|
124
+ Gem.find_files('nacha/record/**/*.rb').reject { |f| f.include?('/spec/') }.each do |file|
62
125
  require File.expand_path(file)
63
126
  end
64
127
 
65
- require 'nacha/parser'
128
+ # Load the parser after the records have been defined
66
129
 
130
+ require 'nacha/parser'