class DTAFile

Attributes

records[R]

Public Class Methods

create(path) { |dta_file| ... } click to toggle source
# File lib/payment_dta/dta_file.rb, line 37
def self.create(path)
  dta_file = self.new(path)
  yield dta_file
  dta_file.write_file
  dta_file
end
new(path, transaction_number = rand(100000000000).to_s) click to toggle source
# File lib/payment_dta/dta_file.rb, line 8
def initialize(path, transaction_number = rand(100000000000).to_s)
  @transaction_number = transaction_number.to_s
  @path = path
  @records = SortedSet.new
end

Public Instance Methods

<<(record) click to toggle source
# File lib/payment_dta/dta_file.rb, line 27
def <<(record)
  record.transaction_number = @transaction_number
  @records << record
  recalculate_entry_sequence_numbers
end
dta_string() click to toggle source
# File lib/payment_dta/dta_file.rb, line 33
def dta_string
  (@records.map(&:to_dta) << build_total_record.to_dta) * "\n" << "\n"
end
total() click to toggle source
# File lib/payment_dta/dta_file.rb, line 21
def total
  @records.inject(0) do |sum, record|
    sum + BigDecimal.new(record.amount.to_s, 16)
  end
end
write_file() click to toggle source
# File lib/payment_dta/dta_file.rb, line 14
def write_file
  File.open(@path,"w") do |file|
    @records.each{|record| file.puts record.to_dta}
    file.puts build_total_record.to_dta
  end
end

Private Instance Methods

build_total_record() click to toggle source
# File lib/payment_dta/dta_file.rb, line 54
def build_total_record
  TotalRecord.new(
    :total_amount => total,
    :entry_sequence_number => @records.count + 1,
    :data_file_sender_identification => @records.first.data_file_sender_identification
  )
end
recalculate_entry_sequence_numbers() click to toggle source
# File lib/payment_dta/dta_file.rb, line 46
def recalculate_entry_sequence_numbers
  start = 1
  @records.each do |record|
    record.entry_sequence_number = start
    start += 1
  end
end