module ACH::Batch::Builder
Supports building a string representation of a particular instance of an ACH
batch. Supports building ACH
lines. Included by ACH::File
.
Public Instance Methods
Returns total amount of entry and addenda records within batch.
@return [Fixnum]
# File lib/ach/batch/builder.rb, line 22 def entry_addenda_count entries.size + addendas.values.flatten.size end
Returns ‘hashed’ representation of all entries within batch. See NACHA documentation for more details on entry hash.
@return [Fixnum]
# File lib/ach/batch/builder.rb, line 30 def entry_hash entries.map{ |entry| entry.routing_number.to_i / 10 }.compact.inject(&:+) end
Returns true
if any of internal ACH
entries has ‘credit’ transaction code.
@return [Boolean]
# File lib/ach/batch/builder.rb, line 8 def has_credit? entries.any?(&:credit?) end
Returns true
if any internal ACH
entry has ‘debit’ transaction code.
@return [Boolean]
# File lib/ach/batch/builder.rb, line 15 def has_debit? entries.any?(&:debit?) end
Returns ACH
record objects that represent the batch.
@return [Array<ACH::Record::Base>]
# File lib/ach/batch/builder.rb, line 51 def to_ach [header] + fetch_entries + [control] end
Returns total amount of all ‘credit’ entries within a batch.
@return [Fixnum]
# File lib/ach/batch/builder.rb, line 44 def total_credit_amount amount_sum_for(:credit?) end
Returns total amount of all ‘debit’ entries within a batch.
@return [Fixnum]
# File lib/ach/batch/builder.rb, line 37 def total_debit_amount amount_sum_for(:debit?) end
Private Instance Methods
Helper method, returns total amount of all entries within a batch, filtered by meth
@param [Symbol] meth @return [Fixnum]
# File lib/ach/batch/builder.rb, line 65 def amount_sum_for(meth) entries.select(&meth).map{ |entry| entry.amount.to_i }.compact.inject(&:+) || 0 end
Helper method executed just before building a header record for the batch.
# File lib/ach/batch/builder.rb, line 56 def before_header attributes[:service_class_code] ||= (has_debit? && has_credit? ? 200 : has_debit? ? 225 : 220) end
Fetches all internal records (entries and addendas) in right order, i.e. addenda records should be positioned right after corresponding entry records.
@return [Array<ACH::Record::Base>]
# File lib/ach/batch/builder.rb, line 74 def fetch_entries entries.inject([]){ |all, entry| all << entry << addendas[entry] }.flatten.compact end