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 13
def initialize(output, options)
  @output = output
  @options = options
  @lineno = 0
  prepare
  if @options[:write_headers] and @headers
    self << @headers
  end
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

  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 46
def rewind
  @lineno = 0
  @headers = nil if @options[:headers].nil?
end