lib/io_streams/row/reader.rb in iostreams-0.15.0 vs lib/io_streams/row/reader.rb in iostreams-0.16.0
- old
+ new
@@ -4,21 +4,24 @@
class Reader
# Read a line as an Array at a time from a file or stream.
def self.open(file_name_or_io,
delimiter: nil,
buffer_size: 65_536,
- encoding: UTF8_ENCODING,
- strip_non_printable: false,
file_name: nil,
+ encoding: nil,
+ encode_cleaner: nil,
+ encode_replace: nil,
**args)
if file_name_or_io.is_a?(String)
IOStreams.line_reader(file_name_or_io,
- delimiter: delimiter,
- buffer_size: buffer_size,
- encoding: encoding,
- file_name: file_name,
- strip_non_printable: strip_non_printable) do |io|
+ delimiter: delimiter,
+ buffer_size: buffer_size,
+ file_name: file_name,
+ encoding: encoding,
+ encode_cleaner: encode_cleaner,
+ encode_replace: encode_replace
+ ) do |io|
yield new(io, file_name: file_name, **args)
end
else
yield new(file_name_or_io, **args)
end
@@ -39,22 +42,18 @@
@delimited = delimited
@cleanse_header = cleanse_header
end
def each
- delimited.each do |line|
- if tabular.requires_header?
- columns = tabular.parse_header(line)
- tabular.cleanse_header! if cleanse_header
+ @delimited.each do |line|
+ if @tabular.header?
+ columns = @tabular.parse_header(line)
+ @tabular.cleanse_header! if @cleanse_header
yield columns
else
- yield tabular.row_parse(line)
+ yield @tabular.row_parse(line)
end
end
end
-
- private
-
- attr_reader :tabular, :delimited, :cleanse_header
end
end
end