Class: CsvBuilder::FilterProxy
- Defined in:
- lib/csv_builder/filter_proxy.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Proxy
Instance Method Summary collapse
-
#<<(row) ⇒ Object
(also: #add_row)
Transliterate before passing to CSV so that the right characters (e.g. quotes) get escaped.
-
#initialize(data, options = {}) ⇒ FilterProxy
constructor
Transliterate into the required encoding if necessary.
Methods inherited from Proxy
Constructor Details
#initialize(data, options = {}) ⇒ FilterProxy
Transliterate into the required encoding if necessary
11 12 13 14 15 16 17 18 19 |
# File 'lib/csv_builder/filter_proxy.rb', line 11 def initialize(data, = {}) @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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class CsvBuilder::Proxy
Instance Method Details
#<<(row) ⇒ Object Also known as: add_row
Transliterate before passing to CSV so that the right characters (e.g. quotes) get escaped
22 23 24 25 26 27 28 29 30 31 32 33 |
# 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 |