lib/smarter_csv.rb in smarter_csv-1.7.1 vs lib/smarter_csv.rb in smarter_csv-1.7.2
- old
+ new
@@ -1,10 +1,12 @@
# frozen_string_literal: true
require_relative "extensions/hash"
require_relative "smarter_csv/version"
+
require_relative "smarter_csv/smarter_csv" unless ENV['CI'] # does not compile/link in CI?
+# require 'smarter_csv.bundle' unless ENV['CI'] # does not compile/link in CI?
module SmarterCSV
class SmarterCSVException < StandardError; end
class HeaderSizeMismatch < SmarterCSVException; end
class IncorrectOption < SmarterCSVException; end
@@ -127,10 +129,12 @@
end
end
next if options[:remove_empty_hashes] && hash.empty?
+ hash[:csv_line_number] = @csv_line_count if options[:with_line_numbers]
+
if use_chunks
chunk << hash # append temp result to chunk
if chunk.size >= chunk_size || fh.eof? # if chunk if full, or EOF reached
# do something with the chunk
@@ -228,10 +232,11 @@
strip_chars_from_headers: nil,
strip_whitespace: true,
user_provided_headers: nil,
value_converters: nil,
verbose: false,
+ with_line_numbers: false,
}
end
def readline_with_counts(filehandle, options)
line = filehandle.readline(options[:row_sep])
@@ -245,15 +250,15 @@
###
def parse(line, options, header_size = nil)
# puts "SmarterCSV.parse OPTIONS: #{options[:acceleration]}" if options[:verbose]
if options[:acceleration] && has_acceleration?
- # puts "NOTICE: Accelerated SmarterCSV / #{options[:acceleration]}" if options[:verbose]
+ # :nocov:
has_quotes = line =~ /#{options[:quote_char]}/
elements = parse_csv_line_c(line, options[:col_sep], options[:quote_char], header_size)
elements.map!{|x| cleanup_quotes(x, options[:quote_char])} if has_quotes
return [elements, elements.size]
-
+ # :nocov:
else
# puts "WARNING: SmarterCSV is using un-accelerated parsing of lines. Check options[:acceleration]"
return parse_csv_line_ruby(line, options, header_size)
end
end