class Guevara::Nacha

Attributes

attributes[R]
batches[R]

Public Class Methods

new(attributes) click to toggle source
# File lib/guevara/nacha.rb, line 10
def initialize attributes
  self.batches = attributes.delete(:batches)
  @attributes = attributes
end

Public Instance Methods

batches=(batches) click to toggle source
# File lib/guevara/nacha.rb, line 15
def batches= batches
  @batches = batches.each_with_index.map do |batch_attributes, index|
    batch_attributes[:number] = index + 1
    Batch.new(batch_attributes)
  end
end
file_control() click to toggle source
# 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() click to toggle source
# File lib/guevara/nacha.rb, line 30
def file_header
  FileHeader.new attributes
end
to_s() click to toggle source
# 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() { |b| ... } click to toggle source
# File lib/guevara/nacha.rb, line 34
def total
  batches.
    map { |b| yield b }.
    reduce(:+)
end