Class CSV::Writer
In: lib/csv.rb
Parent: Object

CSV formatted string/stream writer.

EXAMPLE

  Write rows to 'csvout' file.

  outfile = File.open('csvout', 'wb')
  CSV::Writer.generate(outfile) do |csv|
    csv << ['c1', nil, '', '"', "\r\n", 'c2']
    ...
  end

  outfile.close

Methods

<<   add_row   close   create   generate   new   terminate  

Public Class methods

str_or_writable must handle ’<<(string)’.

[Source]

     # File lib/csv.rb, line 686
686:     def Writer.create(str_or_writable, fs = ',', rs = nil)
687:       BasicWriter.new(str_or_writable, fs, rs)
688:     end

Given block is called with the writer instance. str_or_writable must handle ’<<(string)’.

[Source]

     # File lib/csv.rb, line 674
674:     def Writer.generate(str_or_writable, fs = ',', rs = nil, &block)
675:       writer = Writer.create(str_or_writable, fs, rs)
676:       if block
677:         yield(writer)
678:         writer.close
679:         nil
680:       else
681:         writer
682:       end
683:     end

[Source]

     # File lib/csv.rb, line 703
703:     def initialize(dev)
704:       raise RuntimeError.new('Do not instanciate this class directly.')
705:     end

Public Instance methods

dump CSV stream to the device. argument must be an Array of String.

[Source]

     # File lib/csv.rb, line 691
691:     def <<(row)
692:       CSV.generate_row(row, row.size, @dev, @fs, @rs)
693:       self
694:     end
add_row(row)

Alias for #<<

[Source]

     # File lib/csv.rb, line 697
697:     def close
698:       terminate
699:     end

Private Instance methods

[Source]

     # File lib/csv.rb, line 707
707:     def terminate
708:       # Define if needed.
709:     end

[Validate]