A RubyMotion friendly CSV parser gem
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app
lib
resources
spec
.gitignore
.travis.yml
Gemfile
Gemfile.lock
LICENSE
README.md
Rakefile
motion-csv.gemspec

README.md

motion-csv

Build Status Code Climate

This is a RubyMotion friendly port of fasterer-csv by Mason: http://rubygems.org/gems/fasterer-csv

Installation

Add this line to your application's Gemfile:

gem 'motion-csv'

And then execute:

$ bundle

Or install it yourself as:

$ gem install motion-csv

Usage

Check out the specs directory for usage examples, but here's a few brief examples:

Standard Usage

csv_string = "a,b,c,d\n1,2,3,4\n5,6,7,whatever\n"
csv = MotionCSV.parse(csv_string)

puts csv.headers # [:a, :b, :c, :d]
puts csv.first[:b] # 2
puts csv.last[:d] # "whatever"

Generating a CSV String

MotionCSV.generate do |csv|
  csv << ["row", "of", "CSV", "data"]
  csv << ["another", "row"]
end
# "row,of,CSV,data\nanother,row\n"

Convert an Array to CSV

This uses a convenience method on the Array class. You can pass it a single or two-dimensional array.

["testing", "arrays"].to_csv
# "testing,arrays\n"
[
  ['array1', 'stuff'],
  ['array2', 'more stuff']
].to_csv
# "array1,stuff\narray2,more stuff\n"

Parse a String

This uses a convenience method on the String class.

"header1,header2\nCSV,String".parse_csv
# [["CSV", "String"]]

Tests

To run the testing suite, run rake spec.

Contributing

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