Skip to content

Instantly share code, notes, and snippets.

@dleavitt
Created August 20, 2014 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dleavitt/c1375737d88e2bc28194 to your computer and use it in GitHub Desktop.
Save dleavitt/c1375737d88e2bc28194 to your computer and use it in GitHub Desktop.
CSV_SETTINGS = {
headers: true, # first row is headers
header_converters: :symbol, # convert headers to symbols
converters: [
-> (f) { f.present? ? f : nil }, # convert empty cells to nil
-> (f) { f.respond_to?(:gsub) ? f.gsub(/\s+$/, '') : f }, # convert whitespace to nil
:all # converts things to numbers and dates
]
}
CSV.parse(name, CSV_SETTINGS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment