Class: Mysql2xxxx::CSV

Inherits:
Writer
  • Object
show all
Defined in:
lib/mysql2xxxx/writer/csv.rb

Constant Summary collapse

SLASH_N =
'\N'.freeze

Constants inherited from Writer

Writer::ICONV_FROM, Writer::ICONV_TO, Writer::MYSQL_CHARSET

Instance Attribute Summary

Attributes inherited from Writer

#config

Instance Method Summary collapse

Methods inherited from Writer

#close, #dbh, #initialize, #keys, #last_statement, #recode_as_utf8, #result, #stream_arrays, #stream_hashes, #to_path, #to_s, #to_stdout

Constructor Details

This class inherits a constructor from Mysql2xxxx::Writer

Instance Method Details

#to_file(f) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/mysql2xxxx/writer/csv.rb', line 10

def to_file(f)
  slash_n = config.slash_n

  if slash_n
    f.write keys.map { |v| v.nil? ? SLASH_N : v }.to_csv
  else
    f.write keys.to_csv
  end
  
  stream_arrays do |ary|
    if slash_n
      f.write ary.map { |v| v.nil? ? SLASH_N : v }.to_csv
    else
      f.write ary.to_csv
    end
  end
  nil
end