Module: Nacha

Defined in:
lib/nacha.rb,
lib/nacha/version.rb,
lib/nacha/has_errors.rb,
lib/nacha/record/base.rb,
lib/nacha/record/filler.rb,
lib/nacha/record/ccd_addenda.rb,
lib/nacha/record/cie_addenda.rb,
lib/nacha/record/ctx_addenda.rb,
lib/nacha/record/dne_addenda.rb,
lib/nacha/record/enr_addenda.rb,
lib/nacha/record/file_header.rb,
lib/nacha/record/mte_addenda.rb,
lib/nacha/record/pos_addenda.rb,
lib/nacha/record/ppd_addenda.rb,
lib/nacha/record/shr_addenda.rb,
lib/nacha/record/trx_addenda.rb,
lib/nacha/record/web_addenda.rb,
lib/nacha/record/batch_header.rb,
lib/nacha/record/file_control.rb,
lib/nacha/record/batch_control.rb,
lib/nacha/record/adv_file_header.rb,
lib/nacha/record/ack_entry_detail.rb,
lib/nacha/record/adv_entry_detail.rb,
lib/nacha/record/adv_file_control.rb,
lib/nacha/record/arc_entry_detail.rb,
lib/nacha/record/boc_entry_detail.rb,
lib/nacha/record/ccd_entry_detail.rb,
lib/nacha/record/cie_entry_detail.rb,
lib/nacha/record/dne_entry_detail.rb,
lib/nacha/record/enr_entry_detail.rb,
lib/nacha/record/iat_batch_header.rb,
lib/nacha/record/iat_entry_detail.rb,
lib/nacha/record/mte_entry_detail.rb,
lib/nacha/record/pop_entry_detail.rb,
lib/nacha/record/pos_entry_detail.rb,
lib/nacha/record/ppd_entry_detail.rb,
lib/nacha/record/rck_entry_detail.rb,
lib/nacha/record/shr_entry_detail.rb,
lib/nacha/record/tel_entry_detail.rb,
lib/nacha/record/trc_entry_detail.rb,
lib/nacha/record/trx_entry_detail.rb,
lib/nacha/record/web_entry_detail.rb,
lib/nacha/record/xck_entry_detail.rb,
lib/nacha/record/adv_batch_control.rb,
lib/nacha/record/fifth_iat_addenda.rb,
lib/nacha/record/first_iat_addenda.rb,
lib/nacha/record/sixth_iat_addenda.rb,
lib/nacha/record/third_iat_addenda.rb,
lib/nacha/record/detail_record_type.rb,
lib/nacha/record/filler_record_type.rb,
lib/nacha/record/fourth_iat_addenda.rb,
lib/nacha/record/second_iat_addenda.rb,
lib/nacha/record/addenda_record_type.rb,
lib/nacha/record/seventh_iat_addenda.rb,
lib/nacha/record/file_header_record_type.rb,
lib/nacha/record/batch_header_record_type.rb,
lib/nacha/record/file_control_record_type.rb,
lib/nacha/record/batch_control_record_type.rb,
lib/nacha/record/ctx_corporate_entry_detail.rb,
lib/nacha/record/validations/field_validations.rb,
lib/nacha/record/validations/record_validations.rb,
lib/nacha/record/iat_remittance_information_addenda.rb,
lib/nacha/record/iat_foreign_coorespondent_bank_information_addenda.rb

Overview

:reek:TooManyInstanceVariables, :reek:TooManyMethods

Defined Under Namespace

Modules: HasErrors, Record, Version Classes: AbaNumber, AchDate, Field, Numeric, Parser, ParserContext

Constant Summary collapse

STANDARD_ENTRY_CLASS_CODES =
%w[ACK ADV ARC ATX BOC CCD PPD CIE
COR CTX DNE ENR IAT POP POS SHR
MTE RCK TEL TRC TRX WEB XCK].freeze
SERVICE_CLASS_CODES =
%w[200 220 225 280].freeze
CREDIT_TRANSACTION_CODES =
%w[20 21 22 23 24 30 31 32 33 34 41 42
43 44 51 52 53 54 81 83 85 87].freeze
DEBIT_TRANSACTION_CODES =
%w[25 26 27 28 29 35 36 37 38 39 46 47
48 49 55 56 82 84 86 88].freeze
TRANSACTION_CODES =
(CREDIT_TRANSACTION_CODES + DEBIT_TRANSACTION_CODES).freeze
VERSION =
Version::STRING

Class Method Summary collapse

Class Method Details

.ach_record_typesArray<String>

Returns an array of all currently registered ACH record type class names.

Returns:

  • (Array<String>)

    An array of ACH record class names.



57
58
59
# File 'lib/nacha.rb', line 57

def ach_record_types
  @ach_record_types || []
end

.add_ach_record_type(klass) ⇒ void

This method returns an undefined value.

Adds a new ACH record type class to the list of defined record types. This is used internally by the parser to determine which record classes are available for parsing a NACHA file. As the ‘nacha_field` method is executed for each of the record types, these record types are added to the Nacha module’s class variable ‘@@ach_record_types`.

Parameters:

  • klass (Class, String)

    The record class or its name (as a String) to add.



46
47
48
49
50
51
52
# File 'lib/nacha.rb', line 46

def add_ach_record_type(klass)
  return unless klass

  klass = klass.to_s
  @ach_record_types ||= []
  @ach_record_types << klass unless @ach_record_types.include?(klass)
end

.parse(object) ⇒ Nacha::Record::Base

Parses a NACHA file or string into a structured object representation.

Parameters:

  • object (String, File, IO)

    The input to parse, either a string containing NACHA data or an IO object (e.g., a File) representing the NACHA file.

Returns:



74
75
76
77
78
79
80
81
# File 'lib/nacha.rb', line 74

def parse(object)
  parser = Nacha::Parser.new
  if object.is_a?(String)
    parser.parse_string(object)
  else
    parser.parse_file(object)
  end
end

.record_name(str) ⇒ String

Converts a given string into a underscored, lowercase record name. This is typically used to derive a human-readable or programmatic name from a class name or similar string.

Parameters:

  • str (String)

    The string to convert.

Returns:

  • (String)

    The underscored and lowercased record name.



89
90
91
# File 'lib/nacha.rb', line 89

def record_name(str)
  underscore(str.to_s).split('/').last
end

.to_hObject



61
62
63
64
65
66
67
# File 'lib/nacha.rb', line 61

def to_h
  types_hash = {}
  ach_record_types.each do |record_type|
    types_hash.merge! Object.const_get(record_type).to_h
  end
  types_hash
end

.underscore(str) ⇒ String

Converts a camel-cased string to its underscore equivalent. This method handles module namespaces (::) by converting them to slashes.

Parameters:

  • str (String)

    The string to underscore.

Returns:

  • (String)

    The underscored string.



98
99
100
101
102
103
104
# File 'lib/nacha.rb', line 98

def underscore(str)
  str.gsub(/::/, '/')
     .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
     .gsub(/([a-z\d])([A-Z])/, '\1_\2')
     .tr('-', '_')
     .downcase
end