csv_model
=========

[![Build Status](https://travis-ci.org/Scrimmage/csv_model.svg)](https://travis-ci.org/Scrimmage/csv_model)

[![Code Climate](https://codeclimate.com/github/Scrimmage/csv_model.png)](https://codeclimate.com/github/Scrimmage/csv_model)

CSV Model
=========

[![Build Status](https://travis-ci.org/Scrimmage/csv_model.svg)](https://travis-ci.org/Scrimmage/csv_model)

[![Code Climate](https://codeclimate.com/github/Scrimmage/csv_model.png)](https://codeclimate.com/github/Scrimmage/csv_model)

CSV Model is a bulk import library for ActiveRecord. It parses a CSV into memory, validates the structure, can check for duplicates, and creates or updates the relevant record for each row.


Requirements
------------

### Ruby

CSV Model requires Ruby version **>= 2.0.0**


Installation
------------

CSVModel is distributed as a gem, which is how it should be used in your app.

Include the gem in your Gemfile:

```ruby
gem "csv_model", "~> 1.0"
```

Or, if you want to get the latest, you can get master from the main repository:

```ruby
gem "csv_model", :git => "git://github.com/Scrimmage/csv_model.git"
```


Example Usage
-----------

```ruby
options = {
  dry_run: is_dry_run?,
  legal_columns: structure.legal_columns,
  model: model_finder,
  primary_key: structure.primary_key_columns,
  required_columns: structure.required_columns
}

cm = CSVModel::Model.new(data, options)

if cm.structure_valid?
  puts "Found structural errors: #{csv.structure_errors.inspect}"
else
  cm.rows.each do |row|
    puts "Found row #{row.key} with status #{rows.status} and errors #{row.errors.inspect}"
  end
end
```


Internal Notes
--------------

Deployment:

```bash
gem build csv_model.gemspec
gem push csv_model-x.y.z.gem
```

Add basic info to read me.
Add basic info to read me.
