Class: Guevara::Nacha
- Inherits:
-
Object
- Object
- Guevara::Nacha
- Defined in:
- lib/guevara/nacha.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#batches ⇒ Object
Returns the value of attribute batches.
Instance Method Summary collapse
- #file_control ⇒ Object
- #file_header ⇒ Object
-
#initialize(attributes) ⇒ Nacha
constructor
A new instance of Nacha.
- #to_s ⇒ Object
- #total ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Nacha
Returns a new instance of Nacha.
10 11 12 13 |
# File 'lib/guevara/nacha.rb', line 10 def initialize attributes self.batches = attributes.delete(:batches) @attributes = attributes end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
8 9 10 |
# File 'lib/guevara/nacha.rb', line 8 def attributes @attributes end |
#batches ⇒ Object
Returns the value of attribute batches.
8 9 10 |
# File 'lib/guevara/nacha.rb', line 8 def batches @batches end |
Instance Method Details
#file_control ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/guevara/nacha.rb', line 40 def file_control entry_count = total { |b| b.batch_control.attributes[:entry_count] } block_count = entry_count + batches.size * 2 + 2 FileControl.new( batch_count: batches.count, block_count: block_count, entry_count: entry_count, entry_hash: total { |b| b.batch_control.attributes[:entry_hash] }, total_debit: total { |b| b.total('debit') }, total_credit: total { |b| b.total('credit') } ) end |
#file_header ⇒ Object
30 31 32 |
# File 'lib/guevara/nacha.rb', line 30 def file_header FileHeader.new attributes end |
#to_s ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/guevara/nacha.rb', line 22 def to_s file = [] file << file_header.to_s batches.each { |batch| file << batch.to_s } file << file_control.to_s file.join('') end |
#total ⇒ Object
34 35 36 37 38 |
# File 'lib/guevara/nacha.rb', line 34 def total batches. map { |b| yield b }. reduce(:+) end |