Sha256: 691a07eb4ac7ae74d6493fe25a6199c980eb6e12860eb33439c416a6c695d9d4

Contents?: true

Size: 1.02 KB

Versions: 7

Compression:

Stored size: 1.02 KB

Contents

require 'csv'

class Processor

  class << self
    def init
      @qif = QIF.new
    end

    def process stdin, stdout, arguments, options
      if arguments.empty?
        process_file stdin, stdout, options
      else
        arguments.each do |file|
          mode = ['r', options[:encoding]].compact.join(':')
          stream_in = File.open(file, mode)
          stream_out = File.new esub(file, :csv, :qif), "w"
          begin
            process_file stream_in, stream_out, options
          ensure
            stream_in.close
            stream_out.close
          end
        end
      end
    end

    private

    def esub file, old, new
       file.gsub(/\.#{old}$/i, '')+".#{new}"
    end

    def process_file in_stream, out_stream, options
      @qif.reset out_stream, options
      rownum = 0
      CSV.new(in_stream, :col_sep => options[:field_separator]).each do |row|
        rownum += 1
        @qif.header row if rownum == options[:header]
        @qif.push row if rownum > options[:header]
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
csv2qif-1.2013.5 lib/csv2qif/processor.rb
csv2qif-1.0.4 lib/csv2qif/processor.rb
csv2qif-1.0.3 lib/csv2qif/processor.rb
csv2qif-1.0.2 lib/csv2qif/processor.rb
csv2qif-1.0.1 lib/csv2qif/processor.rb
csv2qif-1.0 lib/csv2qif/processor.rb
csv2qif-0.0.4 lib/csv2qif/processor.rb