-
-
Notifications
You must be signed in to change notification settings - Fork 189
Hash Transformations
Hash Transformations are your bread & butter.
They are applied to each row of the CSV file, after SmarterCSV makes a hash out of it.
Hash transformations come in handy when you want to convert data for some of the rows into a different format, e.g. you can turn numerical data in strings into Ruby numbers, or dates in strings into Ruby dates.
As the name says, this strips leading/trailing spaces from your data fields.
This removes hash keys where the value is nil or an empty string.
When you want to convert all numerical values to Ruby numbers. (optional)
This comes in handy if you want to distinguish between numerical values, e.g. quantities, or dollar amounts, and things which are inherently strings, e.g. part numbers, serial numbers, employee numbers, which are numerically looking, but have significant leading zeros. (optional)
After you convert some of your fields to Ruby numbers, you can use this transformation to treat 0 and 0.0 as nil.
You can define your own custom hash transformations using Ruby Procs.
Here you can find the code for the pre-defined hash transformations