Class: ACH::Batch
- Inherits:
-
Object
- Object
- ACH::Batch
- Defined in:
- lib/ach/batch.rb
Instance Attribute Summary collapse
-
#addendas ⇒ Object
readonly
Returns the value of attribute addendas.
-
#control ⇒ Object
readonly
Returns the value of attribute control.
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#full_company_identification ⇒ Object
Returns the value of attribute full_company_identification.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
Instance Method Summary collapse
-
#initialize ⇒ Batch
constructor
A new instance of Batch.
- #to_ach ⇒ Object
Constructor Details
#initialize ⇒ Batch
Returns a new instance of Batch.
9 10 11 12 13 14 |
# File 'lib/ach/batch.rb', line 9 def initialize @entries = [] @addendas = [] @header = Records::BatchHeader.new @control = Records::BatchControl.new end |
Instance Attribute Details
#addendas ⇒ Object (readonly)
Returns the value of attribute addendas.
4 5 6 |
# File 'lib/ach/batch.rb', line 4 def addendas @addendas end |
#control ⇒ Object (readonly)
Returns the value of attribute control.
6 7 8 |
# File 'lib/ach/batch.rb', line 6 def control @control end |
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
3 4 5 |
# File 'lib/ach/batch.rb', line 3 def entries @entries end |
#full_company_identification ⇒ Object
Returns the value of attribute full_company_identification.
7 8 9 |
# File 'lib/ach/batch.rb', line 7 def full_company_identification @full_company_identification end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
5 6 7 |
# File 'lib/ach/batch.rb', line 5 def header @header end |
Instance Method Details
#to_ach ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/ach/batch.rb', line 16 def to_ach @control.entry_count = @entries.map(&:records_count).reduce(:+).to_i @control.debit_total = 0 @control.credit_total = 0 @control.entry_hash = 0 has_debits = false has_credits = false @entries.each do |e| if e.debit? @control.debit_total += e.amount has_debits = true else @control.credit_total += e.amount has_credits = true end @control.entry_hash += (e.routing_number.to_i / 10) # Last digit is not part of Receiving DFI end # Set service class codes if needed if @header.service_class_code.nil? if has_debits && has_credits @header.service_class_code = 200 elsif has_debits @header.service_class_code = 225 else @header.service_class_code = 220 end end if @control.service_class_code.nil? @control.service_class_code = @header.service_class_code end @control.company_identification = @header.company_identification @control.originating_dfi_identification = @header.originating_dfi_identification @control.batch_number = @header.batch_number if last_entry.is_a? ACH::BalancingEntryDetail @control.credit_total = last_entry.amount @control.debit_total = last_entry.amount end [@header] + @entries + @addendas + [@control] end |