diff --git a/lib/guevara/nacha.rb b/lib/guevara/nacha.rb index 8e0d57e..2913190 100644 --- a/lib/guevara/nacha.rb +++ b/lib/guevara/nacha.rb @@ -38,8 +38,10 @@ def total end def file_control - entry_count = total { |b| b.batch_control.attributes[:entry_count] } - block_count = entry_count + batches.size * 2 + 2 + entry_count = total { |b| b.batch_control.attributes[:entry_count] } + record_count = entry_count + batches.size * 2 + 2 + block_count = (record_count/10.0).ceil # Count of the number of blocks of 10 rows within the file. https://achdevguide.nacha.org/ach-file-details + FileControl.new( batch_count: batches.count, block_count: block_count, diff --git a/test/test_file_generation.rb b/test/test_file_generation.rb index b73f9a8..4cf161c 100644 --- a/test/test_file_generation.rb +++ b/test/test_file_generation.rb @@ -12,7 +12,7 @@ 6271031001953ACCOUNT234 0000001600FD00AFA8A0F7 marge baker 1123456780000001 705wellsville|KS|66092|101 2nd st| 00010000001 82000000020010310019000000001600000000000000 Ruby123 123456780000001 -9000001000006000000020010310019000000001600000000000000 +9000001000001000000020010310019000000001600000000000000 NACHA nacha = Guevara::Nacha.new sample_nacha @@ -50,3 +50,39 @@ nacha = Guevara::Nacha.new nacha_attributes assert lines(nacha).size > 10 end + +test 'calculate block_count (22 lines => 3 block_count)' do + expected = < batches) + + nacha = Guevara::Nacha.new nacha_attributes + nacha.to_s.lines.to_a.each_with_index do |line, index| + debugger_equal line, expected.lines.to_a[index] + end +end