Skip to content
Marshall Strong edited this page Jul 20, 2021 · 26 revisions

SmarterCSV 2 is a Ruby Gem for smarter importing of CSV Files as Arrays of Hashes, suitable for parallel processing with Sidekiq or Resque, as well as direct processing of the resulting hashes with Rails, e.g. ActiveRecord or Mongoid.

Why?

Ruby's CSV library's API is pretty old, and its processing of CSV-files returning Arrays of Arrays feels 'very close to the metal'. The output is not easy to use - especially not if you want to create database records from it. Another shortcoming is that Ruby's CSV library does not have good support for huge CSV-files, e.g. there is no support for 'chunking' and/or parallel processing of the CSV-content (e.g. with Resque or Sidekiq),

As the existing CSV libraries didn't fit my needs, I was writing my own CSV processing - specifically for use in connection with Rails ORMs like Mongoid, MongoMapper or ActiveRecord. In those ORMs you can easily pass a hash with attribute/value pairs to the create() method. The lower-level Mongo driver and Moped also accept larger arrays of such hashes to create a larger amount of records quickly with just one call.

Contents

Clone this wiki locally