Sha256: 5c36f11f26408ffafcf568eff42bc2d736e0dcc353a9fe2309028ae1486a063e

Contents?: true

Size: 1.26 KB

Versions: 19

Compression:

Stored size: 1.26 KB

Contents

#!/usr/local/bin/ruby -w

# csv_rails_import.rb
#
#  Created by James Edward Gray II on 2006-11-05.
#  Copyright 2006 Gray Productions. All rights reserved.

require "faster_csv"

CSV_FILE_PATH = File.join(File.dirname(__FILE__), "output.csv")

# writing to a file
FasterCSV.open(CSV_FILE_PATH, "w") do |csv|
  csv << %w[first last]
  csv << %w[James Gray]
  csv << %w[Dana Gray]
end
puts File.read(CSV_FILE_PATH)
# >> first,last
# >> James,Gray
# >> Dana,Gray

# appending to an existing file
FasterCSV.open(CSV_FILE_PATH, "a") do |csv|
  csv << %w[Gypsy]
  csv << %w[Storm]
end
puts File.read(CSV_FILE_PATH)
# >> first,last
# >> James,Gray
# >> Dana,Gray
# >> Gypsy
# >> Storm

# writing to a string
csv_str = FasterCSV.generate do |csv|
  csv << %w[first last]
  csv << %w[James Gray]
  csv << %w[Dana Gray]
end
puts csv_str
# >> first,last
# >> James,Gray
# >> Dana,Gray

# appending to an existing string
FasterCSV.generate(csv_str) do |csv|
  csv << %w[Gypsy]
  csv << %w[Storm]
end
puts csv_str
# >> first,last
# >> James,Gray
# >> Dana,Gray
# >> Gypsy
# >> Storm

# changing the output format
csv_str = FasterCSV.generate(:col_sep => "\t") do |csv|
  csv << %w[first last]
  csv << %w[James Gray]
  csv << %w[Dana Gray]
end
puts csv_str
# >> first	last
# >> James	Gray
# >> Dana	Gray

Version data entries

19 entries across 19 versions & 6 rubygems

Version Path
asana2flowdock-1.0.0 vendor/bundle/ruby/1.9.1/gems/fastercsv-1.5.5/examples/csv_writing.rb
StephanZ-fastercsv-1.4.1 examples/csv_writing.rb
b2b2dot0-fastercsv-1.4.1 examples/csv_writing.rb
fastercsv-1.5.5 examples/csv_writing.rb
glennfu-faster_csv-1.5.5.1 examples/csv_writing.rb
fastercsv-1.5.4 examples/csv_writing.rb
rw_fastercsv-1.5.7 examples/csv_writing.rb
rw_fastercsv-1.5.6 examples/csv_writing.rb
fastercsv-1.5.3 examples/csv_writing.rb
fastercsv-1.5.1 examples/csv_writing.rb
fastercsv-1.1.0 examples/csv_writing.rb
fastercsv-1.0.0 examples/csv_writing.rb
fastercsv-1.1.1 examples/csv_writing.rb
fastercsv-1.2.0 examples/csv_writing.rb
fastercsv-1.2.2 examples/csv_writing.rb
fastercsv-1.2.1 examples/csv_writing.rb
fastercsv-1.2.3 examples/csv_writing.rb
fastercsv-1.5.0 examples/csv_writing.rb
fastercsv-1.4.0 examples/csv_writing.rb