0

The SmarterCSV wiki page for Basics says that it's possible to retain blank strings for columns that don't have any data (consecutive commas), but I couldn't find additional information on how to do that.

I assume it's something to do with the data validations step, but I can't figure out what. Thanks!

sameers
  • 4,855
  • 3
  • 35
  • 44

1 Answers1

1

I haven't played with this gem but it looks like you have a few options that you can pass in:

:downcase_header
:strings_as_keys
:remove_zero_values
:remove_values_matching
:remove_empty_hashes
:convert_values_to_numeric

In this case, looks like you might want to set remove_empty_values to false. This works in the last v1 (1.2.6) version of the gem.

In v2, which is still in pre-release, the format is to use the hash_transformations option to the process method, and to set it as follows: [:none, :strip_spaces] This first turns off all transformations and then turns on the ones you want, so in this case, the removal of blank values is now turned off.

sameers
  • 4,855
  • 3
  • 35
  • 44
Huy
  • 10,806
  • 13
  • 55
  • 99
  • Your answer is almost correct - the option to change for what I wanted is `remove_empty_values` and it needs to be set to `false`. The relevant code is in `lib/smarter_csv/smarter_csv.rb` in the gem. I am happy to mark your answer the right one if you can make that change. – sameers Jun 14 '19 at 21:27
  • @sameers Updated answer – Huy Jun 14 '19 at 23:20