Sha256: 77b38710861298bbe1a3954343812ef46a1751f5ad7847fb5f12fe5a0dbe0a58

Contents?: true

Size: 752 Bytes

Versions: 3

Compression:

Stored size: 752 Bytes

Contents

require 'csv'

module Dumpster
  module CSV

    class Writer
      def initialize(model)
        @model = model
      end

      def write_to(io)
        csv = build_csv(io)
        @model.each do |row|
          csv << row
        end
      end

      def write_to_file(path)
        File.open(path, 'w+') do |file|
          write_to file
        end
      end

      def write_to_string
        require 'stringio'
        io = StringIO.new
        write_to(io)
        io.rewind
        io.readlines.join
      end

      def build_csv(io)
        ::CSV.new(io, csv_options)
      end

      def csv_options
        {}
      end
    end

    class WindowsWriter < Writer
      def csv_options
        {:col_sep => ';'}
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
dumpster-0.3.0 lib/dumpster/csv.rb
dumpster-0.2.0 lib/dumpster/csv.rb
dumpster-0.1.1 lib/dumpster/csv.rb