class CsvBuilder::FilterProxy

Public Class Methods

new(data, options = {}) click to toggle source

Transliterate into the required encoding if necessary

# File lib/csv_builder/filter_proxy.rb, line 11
def initialize(data, options = {})
  @options = options.dup

  #@options.reverse_merge!(:input_encoding => 'UTF-8', :output_encoding => 'LATIN1')
  @options.reverse_merge!(:input_encoding => DEFAULT_INPUT_ENCODING, :output_encoding => DEFAULT_OUTPUT_ENCODING)

  @input_encoding  = @options.delete(:input_encoding)
  @output_encoding = @options.delete(:output_encoding)
end

Public Instance Methods

<<(row) click to toggle source

Transliterate before passing to CSV so that the right characters (e.g. quotes) get escaped

# File lib/csv_builder/filter_proxy.rb, line 22
def <<(row)
  begin
    base << [*row].map do |value|
      v = value.to_s
      v.force_encoding(@input_encoding)
      v.encode(@output_encoding, :undef => :replace)
      v.encode!
    end
  rescue
    base << [*row]
  end
end
Also aliased as: add_row
add_row(row)
Alias for: <<