lib/io_streams/row/writer.rb in iostreams-0.15.0 vs lib/io_streams/row/writer.rb in iostreams-0.16.0

- old
+ new

@@ -11,16 +11,18 @@ # Output: # ... # class Writer # Write a record as a Hash at a time to a file or stream. - def self.open(file_name_or_io, delimiter: $/, encoding: UTF8_ENCODING, strip_non_printable: false, **args) + def self.open(file_name_or_io, delimiter: $/, encoding: nil, encode_cleaner: nil, encode_replace: nil, **args) if file_name_or_io.is_a?(String) IOStreams.line_writer(file_name_or_io, - delimiter: delimiter, - encoding: encoding, - strip_non_printable: strip_non_printable) do |io| + delimiter: delimiter, + encoding: encoding, + encode_cleaner: encode_cleaner, + encode_replace: encode_replace + ) do |io| yield new(io, **args) end else yield new(file_name_or_io, **args) end @@ -41,22 +43,22 @@ def initialize(delimited, columns: nil, **args) @tabular = IOStreams::Tabular.new(columns: columns, **args) @delimited = delimited # Render header line when `columns` is supplied. - delimited << @tabular.render(columns) if columns && @tabular.requires_header? + delimited << @tabular.render_header if columns && @tabular.requires_header? end # Supply a hash or an array to render def <<(array) raise(ArgumentError, 'Must supply an Array') unless array.is_a?(Array) - # If header (columns) was not supplied as an argument, assume first line is the header. - tabular.header.columns = array if tabular.requires_header? - delimited << tabular.render(array) + if @tabular.header? + # If header (columns) was not supplied as an argument, assume first line is the header. + @tabular.header.columns = array + @delimited << @tabular.render_header + else + @delimited << @tabular.render(array) + end end - - private - - attr_reader :tabular, :delimited end end end