File tree Expand file tree Collapse file tree 6 files changed +31
-9
lines changed
Expand file tree Collapse file tree 6 files changed +31
-9
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,12 @@ module ACH
2020 225 , # ACH Debits Only
2121 280 # ACH Automated Accounting Advices
2222 ]
23+
24+ DEFAULT_EOL = "\r \n "
25+
26+ def self . eol
27+ DEFAULT_EOL
28+ end
2329end
2430
2531require 'time'
Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ def initialize data=nil
2424
2525
2626 # @param eol [String] Line ending, default to CRLF
27- def to_s eol = " \r \n "
27+ def to_s eol = ACH . eol
2828 records = [ ]
2929 records << @header
3030
@@ -55,10 +55,10 @@ def to_s eol = "\r\n"
5555 @control . entry_hash += batch . control . entry_hash
5656 end
5757
58- records . collect { |r | r . to_ach } . join ( eol ) + eol
58+ records . collect { |r | r . to_ach ( eol : eol ) } . join ( eol ) + eol
5959 end
6060
61- def report
61+ def report eol : ACH . eol
6262 to_s # To ensure correct records
6363 lines = [ ]
6464
@@ -74,7 +74,7 @@ def report
7474 lines << left_justify ( "Credit Total: " , 25 ) +
7575 sprintf ( "% 7d.%02d" , @control . credit_total / 100 , @control . credit_total % 100 )
7676
77- lines . join ( " \r \n " )
77+ lines . join ( eol )
7878 end
7979
8080 def parse_fixed data
Original file line number Diff line number Diff line change @@ -58,9 +58,9 @@ def to_ach
5858
5959 [ @header ] + @entries + @addendas + [ @control ]
6060 end
61-
61+
6262 private
63-
63+
6464 def last_entry
6565 @last_entry ||= @entries . last
6666 end
Original file line number Diff line number Diff line change @@ -54,15 +54,15 @@ def addenda_records?
5454 return !self . addenda . empty?
5555 end
5656
57- def to_ach
57+ def to_ach eol : ACH . eol
5858 self . addenda_record_indicator = ( self . addenda . empty? ? 0 : 1 ) if self . respond_to? ( :addenda_record_indicator )
5959 self . number_of_addenda_records = self . addenda . length if self . respond_to? ( :number_of_addenda_records )
6060
6161 ach_string = super
6262
6363 self . addenda . each { |a |
6464 a . entry_detail_sequence_number = self . trace_number
65- ach_string << " \r \n " + a . to_ach
65+ ach_string << eol + a . to_ach
6666 }
6767 return ach_string
6868 end
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ def fields
1313
1414 attr_accessor :case_sensitive
1515
16- def to_ach
16+ def to_ach eol : nil
1717 to_ach = self . class . fields . collect { |f | send ( "#{ f } _to_ach" ) } . join ( '' )
1818 case_sensitive ? to_ach : to_ach . upcase
1919 end
Original file line number Diff line number Diff line change @@ -92,6 +92,7 @@ def add_balancing_entry_detail(batch)
9292 it 'shows the offset line' do
9393 expect ( ach_file . to_s . split ( "\r \n " ) [ 6 ] ) . to eq ( full_file [ 6 ] )
9494 end
95+
9596 it 'shows the debit and credit on line 7' do
9697 expect ( ach_file . to_s . split ( "\r \n " ) [ 7 ] ) . to eq ( full_file [ 7 ] )
9798 end
@@ -198,6 +199,10 @@ def add_balancing_entry_detail(batch)
198199 end
199200
200201 describe 'eol param' do
202+ before ( :each ) do
203+ add_batch ach_file , 3
204+ end
205+
201206 context 'default' do
202207 subject ( :output ) { ach_file . to_s }
203208
@@ -215,6 +220,17 @@ def add_balancing_entry_detail(batch)
215220 expect ( output [ -2 ..-1 ] ) . to_not eq ( "\r \n " )
216221 expect ( output [ -1 ] ) . to eq ( "\n " )
217222 end
223+
224+ context 'has addendum records' do
225+ it 'accounts for addendum records' do
226+ addendum = ACH ::Addendum . new
227+ addendum . sequence_number = 1
228+ addendum . payment_data = 'Data'
229+
230+ ach_file . batches . first . entries . last . addenda << addendum
231+ expect ( ach_file . to_s ( "\n " ) . include? ( "\r " ) ) . to be ( false )
232+ end
233+ end
218234 end
219235 end
220236 end
You can’t perform that action at this time.
0 commit comments