Sha256: 041156c55e8ccc51cc354548d05853586f5fdd198e78d7b33db59092e4c0b463

Contents?: true

Size: 973 Bytes

Versions: 1

Compression:

Stored size: 973 Bytes

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|
          stream_in = File.open(file, "r")
          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::Reader.parse(in_stream, options[:field_separator]) 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

1 entries across 1 versions & 1 rubygems

Version Path
csv2qif-0.0.1 lib/csv2qif/processor.rb