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_countFixnum

Returns total amount of entry and addenda records within batch.

Returns:

  • (Fixnum)


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

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

#entry_hashFixnum

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

Returns:

  • (Fixnum)


30
31
32
# File 'lib/ach/batch/builder.rb', line 30

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)


8
9
10
# File 'lib/ach/batch/builder.rb', line 8

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

#has_debit?Boolean

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

Returns:

  • (Boolean)


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

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

#to_achArray<ACH::Record::Base>

Returns ACH record objects that represent the batch.

Returns:



51
52
53
# File 'lib/ach/batch/builder.rb', line 51

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

#total_credit_amountFixnum

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

Returns:

  • (Fixnum)


44
45
46
# File 'lib/ach/batch/builder.rb', line 44

def total_credit_amount
  amount_sum_for(:credit?)
end

#total_debit_amountFixnum

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

Returns:

  • (Fixnum)


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

def total_debit_amount
  amount_sum_for(:debit?)
end