Csv2Hash

Code Climate

Dependency Status

Build Status (Travis CI)

Coverage Status

It's DSL for valided and map CSV to Ruby Hash

Installation

Add this line to your application's Gemfile:

gem 'csv2hash'

And then execute:

$ bundle

Or install it yourself as:

$ gem install csv2hash

Usage

You should be declare an definition for you CSV, for each cells you should define what you expect.

Example :

You want first cell parsed should be string with values are 'yes' or 'no' you must fill follow rule :

{ name: 'aswering', type: 'string', values: ['yes', 'no'], position: [0,0] }

All keys as default value, so you can just define this rule :

{ name: 'aswering', values: ['yes', 'no'], position: [0,0] }

You can define message, default is 'undefined :key on :position'

{ name: 'aswering', values: ['yes', 'no'], position: [0,0], message: 'this value is not supported' }

if you insert key on you message they will be substituted

{ ..., message: 'value of :name is not supported, please you one of :values' }

produce ': value of aswering is not supported, please you one of [yes, no]'

Default values

  • message: 'undefined :key on :position'
  • mappable: true
  • type: 'string'
  • values: nil
  • nested: nil
  • allow_blank: false
  • position: nil
  • maptype: 'cell'

Limitations

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request