简体   繁体   English

Ruby SmarterCSV gem保留空白字符串

[英]Ruby SmarterCSV gem keep blank strings

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. 基本SmarterCSV Wiki页面说,可以为没有任何数据的列保留连续的字符串(连续的逗号),但是我找不到有关如何执行此操作的其他信息。

I assume it's something to do with the data validations step, but I can't figure out what. 我认为这与数据验证步骤有关,但我不知道要做什么。 Thanks! 谢谢!

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. 在这种情况下,您可能希望将remove_empty_values设置为false。 This works in the last v1 (1.2.6) version of the gem. 这适用于gem的最新v1(1.2.6)版本。

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. 在仍处于预发行版本的v2中,格式是对process方法使用hash_transformations选项,并将其设置如下: [:none, :strip_spaces]首先关闭所有转换,然后再打开所有转换。您需要,因此在这种情况下,现在将关闭空白值的删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM