class Rocknab::Layouts::CNAB240::Batch

Constants

BATCH_PARAMS
SEGMENT_PARAMS
TRAILER_PARAMS

Public Instance Methods

build() click to toggle source
# File lib/rocknab/layouts/cnab_240/batch.rb, line 16
def build
  [ batch_header, segments, batch_trailer ]
end

Private Instance Methods

batch_header() click to toggle source
# File lib/rocknab/layouts/cnab_240/batch.rb, line 22
def batch_header
  default_params = {
    batch_index: batch_index,
    payment_method: payment_method,
  }
  line_params = params.slice(*BATCH_PARAMS).merge(default_params)

  BatchHeader.new(line_params).build
end
batch_trailer() click to toggle source
# File lib/rocknab/layouts/cnab_240/batch.rb, line 46
def batch_trailer
  default_params = {
    batch_index: batch_index,
    register_count: register_count,
    total_sum: total_sum,
  }
  line_params = params.slice(*TRAILER_PARAMS).merge(default_params)

  BatchTrailer.new(line_params).build
end
doc_type() click to toggle source
# File lib/rocknab/layouts/cnab_240/batch.rb, line 69
def doc_type
  if is_savings && !is_same_bank
    "11"
  else
    ""
  end
end
payment_method() click to toggle source
# File lib/rocknab/layouts/cnab_240/batch.rb, line 57
def payment_method
  if is_same_bank && is_savings
    5
  elsif is_same_bank
    1
  elsif is_ted
    41
  else
    3
  end
end
register_count() click to toggle source
# File lib/rocknab/layouts/cnab_240/batch.rb, line 77
def register_count
  payments.count + 2
end
segments() click to toggle source
# File lib/rocknab/layouts/cnab_240/batch.rb, line 32
def segments
  payments.each_with_index.map do |payment, index|
    default_params = {
      batch_index: batch_index,
      segment_index: index + 1,
      bank_code: params.dig(:bank_code),
      doc_type: doc_type,
    }
    line_params = payment.slice(*SEGMENT_PARAMS).merge(default_params)

    Segment.new(line_params).build
  end
end
total_sum() click to toggle source
# File lib/rocknab/layouts/cnab_240/batch.rb, line 81
def total_sum
  payments.inject(0) do |sum, payment|
    sum + payment.dig(:value)
  end
end