Class: ACH::File

Inherits:
Component show all
Includes:
Builder, TransmissionHeader
Defined in:
lib/ach/file.rb

Overview

An ACH::File instance represents an actual ACH file. Every file has an ACH::File::Header and ACH::File::Control records and a variable number of ACH::Batches. The ACH::File::TransmissionHeader is optional. (Refer to the target financial institution’s documentation.)

Example

# Subclass ACH::File to set default values:
class CustomAchFile < ACH::File
  immediate_dest        '123123123'
  immediate_dest_name   'COMMERCE BANK'
  immediate_origin      '123123123'
  immediate_origin_name 'MYCOMPANY'
end

# Create a new instance:
ach_file = CustomAchFile.new do
  batch(:entry_class_code => "WEB", :company_entry_descr => "TV-TELCOM") do
    effective_date Time.now.strftime('%y%m%d')
    desc_date      Time.now.strftime('%b %d').upcase
    origin_dfi_id "00000000"
    entry :customer_name  => 'JOHN SMITH',
          :customer_acct  => '61242882282',
          :amount         => '2501',
          :routing_number => '010010101',
          :bank_account   => '103030030'
  end
end

# convert to string
ach_file.to_s! # => returns string representation of file

# write to file
ach_file.write('custom_ach.txt')

Defined Under Namespace

Modules: Builder, TransmissionHeader Classes: Control, Header, Reader

Constant Summary

Constants included from Constants

Constants::BATCH_ADDENDA_RECORD_TYPE, Constants::BATCH_CONTROL_RECORD_TYPE, Constants::BATCH_ENTRY_RECORD_TYPE, Constants::BATCH_HEADER_RECORD_TYPE, Constants::BLOCKING_FACTOR, Constants::FILE_CONTROL_RECORD_TYPE, Constants::FILE_HEADER_RECORD_TYPE, Constants::FORMAT_CODE, Constants::RECORD_SIZE, Constants::ROWS_DELIMITER

Instance Attribute Summary

Attributes inherited from Component

#attributes

Class Method Summary collapse

Methods included from TransmissionHeader

#have_transmission_header?, #transmission_header

Methods included from Builder

#batch_count, #block_count, #entry_hash, #file_entry_addenda_count, #record_count, #tail, #tails_count, #to_ach, #to_s!, #total_credit_amount, #total_debit_amount, #write

Methods inherited from Component

#after_initialize, #build_control, #build_header, #control, #fields_for, has_many, #header, inherited, #initialize, #method_missing, method_missing

Methods included from Validations

#errors, #valid?

Constructor Details

This class inherits a constructor from ACH::Component

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ACH::Component

Class Method Details

.read(filename) ⇒ ACH::File

Open a filename and pass its handler to the ACH::Reader object, which uses it as an enum to scan for ACH contents line by line.

Parameters:

  • filename (String)

Returns:



53
54
55
56
57
# File 'lib/ach/file.rb', line 53

def self.read(filename)
  ::File.open(filename) do |fh|
    Reader.new(fh).to_ach
  end
end