Class: ACH::ACHFile
- Inherits:
-
Object
- Object
- ACH::ACHFile
- Includes:
- FieldIdentifiers
- Defined in:
- lib/ach/ach_file.rb
Instance Attribute Summary collapse
-
#batches ⇒ Object
readonly
Returns the value of attribute batches.
-
#control ⇒ Object
readonly
Returns the value of attribute control.
-
#header ⇒ Object
readonly
Returns the value of attribute header.
Instance Method Summary collapse
-
#initialize ⇒ ACHFile
constructor
A new instance of ACHFile.
- #report ⇒ Object
- #to_s ⇒ Object
Methods included from FieldIdentifiers
#const_field, #field, #left_justify, #routing_field, #spaceless_routing_field
Constructor Details
#initialize ⇒ ACHFile
Returns a new instance of ACHFile.
9 10 11 12 13 |
# File 'lib/ach/ach_file.rb', line 9 def initialize @batches = [] @header = Records::FileHeader.new @control = Records::FileControl.new end |
Instance Attribute Details
#batches ⇒ Object (readonly)
Returns the value of attribute batches.
5 6 7 |
# File 'lib/ach/ach_file.rb', line 5 def batches @batches end |
#control ⇒ Object (readonly)
Returns the value of attribute control.
7 8 9 |
# File 'lib/ach/ach_file.rb', line 7 def control @control end |
#header ⇒ Object (readonly)
Returns the value of attribute header.
6 7 8 |
# File 'lib/ach/ach_file.rb', line 6 def header @header end |
Instance Method Details
#report ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ach/ach_file.rb', line 43 def report to_s # To ensure correct records lines = [] @batches.each do | batch | batch.entries.each do | entry | lines << left_justify(entry.individual_name + ": ", 25) + sprintf("% 7d.%02d", entry.amount / 100, entry.amount % 100) end end lines.join("\r\n") end |
#to_s ⇒ Object
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 |
# File 'lib/ach/ach_file.rb', line 15 def to_s records = [] records << @header @batches.each { |b| records += b.to_ach } records << @control nines_needed = 10 - (records.length % 10) nines_needed = nines_needed % 10 nines_needed.times { records << Records::Nines.new() } @control.batch_count = @batches.length @control.block_count = (records.length / 10).ceil @control.entry_count = 0 @control.debit_total = 0 @control.credit_total = 0 @control.entry_hash = 0 @batches.each do | batch | @control.entry_count += batch.entries.length @control.debit_total += batch.control.debit_total @control.credit_total += batch.control.credit_total @control.entry_hash += batch.control.entry_hash end records.collect { |r| r.to_ach }.join("\r\n") + "\r\n" end |