lib/io_streams/row/writer.rb in iostreams-1.1.0 vs lib/io_streams/row/writer.rb in iostreams-1.1.1

- old
+ new

@@ -1,6 +1,6 @@ -require 'csv' +require "csv" module IOStreams module Row # Example: # IOStreams.path("file.csv").writer(:array) do |stream| # stream << ['name', 'address', 'zipcode'] @@ -35,23 +35,21 @@ # format: [Symbol] # :csv, :hash, :array, :json, :psv, :fixed # # For all other parameters, see Tabular::Header.new def initialize(line_writer, columns: nil, **args) - unless line_writer.respond_to?(:<<) - raise(ArgumentError, 'Stream must be a IOStreams::Line::Writer or implement #<<') - end + raise(ArgumentError, "Stream must be a IOStreams::Line::Writer or implement #<<") unless line_writer.respond_to?(:<<) @tabular = IOStreams::Tabular.new(columns: columns, **args) @line_writer = line_writer # Render header line when `columns` is supplied. line_writer << @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) + raise(ArgumentError, "Must supply an Array") unless array.is_a?(Array) if @tabular.header? # If header (columns) was not supplied as an argument, assume first line is the header. @tabular.header.columns = array @line_writer << @tabular.render_header