Sha256: ef7d1c520e03f7e5bd0120de81de5e87fcd51f020d38f1aac6611e6ec10c8b44

Contents?: true

Size: 1.24 KB

Versions: 2

Compression:

Stored size: 1.24 KB

Contents

module Clieop
  module Payment

    class File

      attr_accessor :batches
      attr_reader   :file_info

      def initialize(file_info = {})
        file_info[:date] = Date.today unless file_info[:date]
        file_info[:date] = file_info[:date].strftime('%d%m%y') if file_info[:date].respond_to?(:strftime)
        @file_info = file_info
        @batches = []
      end

      # renders this file as a CLIEOP03 formatted string
      def to_clieop
        clieop_data = Clieop::Payment::Record.new(:file_header, @file_info).to_clieop
        @batches.each { |batch| clieop_data << batch.to_clieop }
        clieop_data << Clieop::Payment::Record.new(:file_footer).to_clieop
      end

      # Alias for to_clieop
      alias_method :to_s, :to_clieop

      def payment_batch(options)
        @batches << Clieop::Payment::Batch.payment_batch(options)
        yield(@batches.last) if block_given?
        return @batches.last
      end

      def invoice_batch(options)
        @batches << Clieop::Payment::Batch.invoice_batch(options)
        yield(@batches.last) if block_given?
        return @batches.last
      end

      def save(filename)
        ::File.open(filename, 'w') do |f|
          f.write(self.to_clieop)
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
clieop-1.0.1 lib/clieop/payment/file.rb
clieop-1.0.0 lib/clieop/payment/file.rb