Sha256: 845bec0337d641dfa33e1224dccd93321bb7b9915a3b04370e36c6052af9df5e

Contents?: true

Size: 605 Bytes

Versions: 2

Compression:

Stored size: 605 Bytes

Contents

if RUBY_VERSION >= '1.9'
  require 'csv'
else
  require 'fastercsv'
end

module Mysql2xxxx
  class CSV
    include ExtraOutputs
    
    attr_reader :properties
    
    def initialize(options = {})
      @properties = Properties.new options
    end
    
    def client
      @client ||= Client.new properties
    end

    def to_file(f)
      keys = nil
      client.select_each(properties.execute) do |hsh|
        unless keys
          keys = hsh.keys
          f.write keys.to_csv
        end
        f.write keys.inject([]) { |memo, k| memo.push hsh[k] }.to_csv
      end
      nil
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mysql2xxxx-0.0.2 lib/mysql2xxxx/csv.rb
mysql2xxxx-0.0.1 lib/mysql2xxxx/csv.rb