lib/ach/file.rb in ach_builder-0.0.1.1 vs lib/ach/file.rb in ach_builder-0.0.2

- old
+ new

@@ -5,14 +5,14 @@ def batch_count batches.length end def block_count - (entry_count / 10.0).ceil + (file_entry_count.to_f / BLOCKING_FACTOR).ceil end - def entry_count + def file_entry_count batches.map{ |b| b.entries.length }.inject(&:+) || 0 end def entry_hash batches.map(&:entry_hash).compact.inject(&:+) @@ -25,14 +25,20 @@ def total_credit_amount batches.map(&:total_credit_amount).compact.inject(&:+) end def to_ach - [header] + batches.map(&:to_ach).flatten + [control] + extra = block_count * BLOCKING_FACTOR - file_entry_count + tail = ([Tail.new] * extra).unshift(control) + [header] + batches.map(&:to_ach).flatten + tail end def to_s! - to_ach.map(&:to_s!).join("\n") + to_ach.map(&:to_s!).join("\r\n") + "\r\n" + end + + def record_count + 2 + batches.length * 2 + file_entry_count end def write filename return false unless valid? ::File.open(filename, 'w') do |fh|