-
-
Notifications
You must be signed in to change notification settings - Fork 190
Header Transformations
Tilo edited this page Feb 13, 2022
·
3 revisions
to disable any pre-existing default settings, so you can start from a clean-slate.
This is the default behavior, as explained in The Basics.
Similar, but strings. Also explained in The Basics.
Don't forget to start with :none
.
With :key_mapping
you can completely or partially re-map your header keys.
Maps keys from -> to, and can map headers to nil
, so they can be omitted from the result hashes.
The key_mapping_spec.rb
has some examples on how to use this.
You can always define your own custom Procs.
camelcase_headers = Proc.new {|headers|
headers.map{|x| x.strip.downcase.gsub(/(\s|\-)+/,'_').split('_').map(&:capitalize).join }
}
options = {
header_transformations: [:none, camelcase_headers ]
}
data = SmarterCSV.process('/tmp/test.csv', options)
=> [{"Category"=>"Red", "FirstName"=>"John", "Age"=>"35"}]