Class: ACH::Batch
- Inherits:
-
Object
- Object
- ACH::Batch
- Defined in:
- lib/ach/batch.rb
Instance Attribute Summary collapse
-
#control ⇒ Object
readonly
Returns the value of attribute control.
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#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.
7 8 9 10 11 |
# File 'lib/ach/batch.rb', line 7 def initialize @entries = [] @header = Records::BatchHeader.new @control = Records::BatchControl.new end |
Instance Attribute Details
#control ⇒ Object (readonly)
Returns the value of attribute control.
5 6 7 |
# File 'lib/ach/batch.rb', line 5 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 |
#header ⇒ Object (readonly)
Returns the value of attribute header.
4 5 6 |
# File 'lib/ach/batch.rb', line 4 def header @header end |
Instance Method Details
#to_ach ⇒ Object
13 14 15 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 |
# File 'lib/ach/batch.rb', line 13 def to_ach @control.entry_count = @entries.length @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 [@header] + @entries + [@control] end |