lib/smarter_csv/options.rb in smarter_csv-1.12.1 vs lib/smarter_csv/options.rb in smarter_csv-1.13.0

- old
+ new

@@ -24,10 +24,11 @@ force_utf8: false, headers_in_file: true, invalid_byte_sequence: '', keep_original_headers: false, key_mapping: nil, + missing_header_prefix: 'column_', quote_char: '"', remove_empty_hashes: true, remove_empty_values: true, remove_unmapped_keys: false, remove_values_matching: nil, @@ -35,10 +36,11 @@ required_headers: nil, required_keys: nil, row_sep: :auto, # was: $/, silence_missing_keys: false, skip_lines: nil, + strict: false, strings_as_keys: false, strip_chars_from_headers: nil, strip_whitespace: true, user_provided_headers: nil, value_converters: nil, @@ -47,9 +49,21 @@ }.freeze # NOTE: this is not called when "parse" methods are tested by themselves def process_options(given_options = {}) puts "User provided options:\n#{pp(given_options)}\n" if given_options[:verbose] + + # Special case for :user_provided_headers: + # + # If we would use the default `headers_in_file: true`, and `:user_provided_headers` are given, + # we could lose the first data row + # + # We now err on the side of treating an actual header as data, rather than losing a data row. + # + if given_options[:user_provided_headers] && !given_options.keys.include?(:headers_in_file) + given_options[:headers_in_file] = false + puts "WARNING: setting `headers_in_file: false` as a precaution to not lose the first row. Set explicitly to `true` if you have headers." + end @options = DEFAULT_OPTIONS.dup.merge!(given_options) # fix invalid input @options[:invalid_byte_sequence] ||= ''