class Ach::BatchControlRecord

Attributes

addenda_count[RW]
batch_number[RW]
company_id[RW]
entry_hash[RW]
msg_authentication_code[RW]
record_type[RW]
routing_num[RW]
service_class_code[RW]
total_credits[RW]
total_debits[RW]

Public Class Methods

decode(record,processor) click to toggle source
# File lib/ach/creator.rb, line 388
def self.decode(record,processor)
  batch_control = CustomOrderedHash.new
  batch_control.insert(:record_type,record[0].chr)
  batch_control.insert(:service_class_code,record[1,3])
  batch_control.insert(:addenda_count,record[4,6])
  batch_control.insert(:entry_hash,record[10,10])
  batch_control.insert(:total_debits, record[20,12])
  batch_control.insert(:total_credits, record[32,12])
  batch_control.insert(:company_id, record[44,10])
  batch_control.insert(:msg_authentication_code, record[54,19])
  batch_control.insert(:reserved,record[73,6])
  batch_control.insert(:routing_num, record[79,8])
  batch_control.insert(:batch_number, record[87,7])
  processor.process(batch_control)
end
new(options={}) click to toggle source
# File lib/ach/creator.rb, line 374
def initialize(options={})
  @record_type = '8'
  @service_class_code = options[:service_class_code]
  @addenda_count = options[:addenda_count]
  @entry_hash=options[:entry_hash]
  @total_debits = options[:total_debits]
  @total_credits = options[:total_credits]
  @company_id = options[:company_id]
  @routing_num = options[:routing_num]
  @batch_number = options[:batch_number]
  @write_to_file = options[:write_to_file]
  encode
end

Protected Instance Methods

encode() click to toggle source
# File lib/ach/creator.rb, line 406
def encode
  begin
    file = @record_type
    file << @service_class_code.to_s
    @addenda_digit_count = @addenda_count.to_s.split(//)
    if @addenda_digit_count.size > 1
      file << @addenda_count.to_s.rjust(5,"0")
    else
      file << @addenda_count.to_s.rjust(6,"0")
    end
    file << @entry_hash.to_s.rjust(10,"0")
    file << @total_debits.rjust(12,"0")
    file << @total_credits.rjust(12,"0")
    file << @company_id.to_s
    file << "".ljust(19)
    file << "".ljust(6)
    file << @routing_num
    @batch_number = "0000000000000" + @batch_number.to_s
    file << @batch_number[-7,7]
    Ach::Creator.write_header(file,@write_to_file)
  rescue Exception => ex
    puts "Exception while writing ach file -- #{ex.class} #{ex.message} #{ex.backtrace.pp_s}"
  end
end