Class: CsvBuilder::TransliteratingFilter
- Inherits:
-
Object
- Object
- CsvBuilder::TransliteratingFilter
- Defined in:
- lib/csv_streamer/transliterating_filter.rb
Instance Method Summary collapse
-
#<<(row) ⇒ Object
(also: #add_row)
Transliterate before passing to FasterCSV so that the right characters (e.g. quotes) get escaped.
-
#initialize(faster_csv, input_encoding = 'UTF-8', output_encoding = 'LATIN1') ⇒ TransliteratingFilter
constructor
Transliterate into the required encoding if necessary.
Constructor Details
#initialize(faster_csv, input_encoding = 'UTF-8', output_encoding = 'LATIN1') ⇒ TransliteratingFilter
Transliterate into the required encoding if necessary
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/csv_streamer/transliterating_filter.rb', line 5 def initialize(faster_csv, input_encoding = 'UTF-8', output_encoding = 'LATIN1') @faster_csv = faster_csv # TODO: do some checking to make sure iconv works correctly in # current environment. See ActiveSupport::Inflector#transliterate # definition for details # # Not using the more standard //IGNORE//TRANSLIT because it raises # Iconv::IllegalSequence for some inputs @iconv = Iconv.new("#{output_encoding}//TRANSLIT//IGNORE", input_encoding) if input_encoding != output_encoding end |
Instance Method Details
#<<(row) ⇒ Object Also known as: add_row
Transliterate before passing to FasterCSV so that the right characters (e.g. quotes) get escaped
18 19 20 |
# File 'lib/csv_streamer/transliterating_filter.rb', line 18 def <<(row) @faster_csv << if @iconv then row.map { |value| @iconv.iconv(value.to_s) } else row end end |