In Files

  • csv/writer.rb

Parent

Methods

CSV::Writer

Attributes

headers[R]
lineno[R]

Public Class Methods

new(output, options) click to toggle source
 
               # File csv/writer.rb, line 12
def initialize(output, options)
  @output = output
  @options = options
  @lineno = 0
  prepare
  if @options[:write_headers] and @headers
    self << @headers
  end
  @fields_converter = @options[:fields_converter]
end
            

Public Instance Methods

<<(row) click to toggle source
 
               # File csv/writer.rb, line 23
def <<(row)
  case row
  when Row
    row = row.fields
  when Hash
    row = @headers.collect {|header| row[header]}
  end

  @headers ||= row if @use_headers
  @lineno += 1

  row = @fields_converter.convert(row, nil, lineno) if @fields_converter

  converted_row = row.collect do |field|
    quote(field)
  end
  line = converted_row.join(@column_separator) + @row_separator
  if @output_encoding
    line = line.encode(@output_encoding)
  end
  @output << line

  self
end
            
rewind() click to toggle source
 
               # File csv/writer.rb, line 48
def rewind
  @lineno = 0
  @headers = nil if @options[:headers].nil?
end