- Create a
foo.csv.yml
config for eachfoo.csv
. require 'csv_transform'
table = Importer.import('foo.csv', HashWithIndifferentAccess)
- Post-process the returned hash as you please.
field
: top-level key which defines the header value for that fieldtype
: snake_case representation of the classdefault_value
: default if a value is ommittedlexicon
: value transformstranslations
: header transforms
{
# Global Options
global: {
headers: {
formatters: [ ]
}
},
# Field-specific Options
fields: {
genus: {
type: symbol
},
period: {
type: symbol
},
continent: {
type: symbol,
default_value: africa
},
diet: {
type: symbol,
lexicon: {
'yes': carnivore,
'no': herbivore
},
translations: [ carnivore ]
},
weight: {
type: integer
},
locomotion_type: {
type: symbol,
translations: [ walking ]
},
description: {
type: string
}
}
}