Module: ACH::Batch::Builder

Included in:
ACH::Batch
Defined in:
lib/ach/batch/builder.rb

Overview

Supports building a string representation of a particular instance of an ACH batch. Supports building ACH lines. Included by ACH::File.

Instance Method Summary collapse

Instance Method Details

#entry_addenda_countObject

Returns total amount of entry and addenda records within batch



16
17
18
# File 'lib/ach/batch/builder.rb', line 16

def entry_addenda_count
  entries.size + addendas.values.flatten.size
end

#entry_hashObject

Returns ‘hashed’ representation of all entries within batch. See NACHA documentation for more details on entry hash



22
23
24
# File 'lib/ach/batch/builder.rb', line 22

def entry_hash
  entries.map{ |entry| entry.routing_number.to_i / 10 }.compact.inject(&:+)
end

#has_credit?Boolean

Returns true if any of internal ACH entries has ‘credit’ transaction code

Returns:

  • (Boolean)


6
7
8
# File 'lib/ach/batch/builder.rb', line 6

def has_credit?
  entries.any?(&:credit?)
end

#has_debit?Boolean

Returns true if any internal ACH entry has ‘debit’ transaction code

Returns:

  • (Boolean)


11
12
13
# File 'lib/ach/batch/builder.rb', line 11

def has_debit?
  entries.any?(&:debit?)
end

#to_achObject

Returns ACH record objects that represent the batch



37
38
39
# File 'lib/ach/batch/builder.rb', line 37

def to_ach
  [header] + fetch_entries + [control]
end

#total_credit_amountObject

Returns total amount of all ‘credit’ entries within a batch



32
33
34
# File 'lib/ach/batch/builder.rb', line 32

def total_credit_amount
  amount_sum_for(:credit?)
end

#total_debit_amountObject

Returns total amount of all ‘debit’ entries within a batch



27
28
29
# File 'lib/ach/batch/builder.rb', line 27

def total_debit_amount
  amount_sum_for(:debit?)
end