Project

enum_csv

0.0
Low commit activity in last 3 years
A long-lived project that still receives updates
EnumCSV exposes a single method, csv, for easily creating CSV output/files from enumerable objects.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

Runtime

>= 0
 Project Readme

EnumCSV¶ ↑

EnumCSV exposes a single method, csv, for easily creating CSV output/files from enumerable objects. It is a simple wrapper class for ruby’s csv library.

Installation¶ ↑

gem install enum_csv

Source Code¶ ↑

Source code is available on GitHub at github.com/jeremyevans/enum_csv

Examples¶ ↑

The default behavior just expects an enumerable of arrays (such as an array of arrays), and returns a string containing the CSV output:

EnumCSV.csv([[1, 2]]) => "1,2\n"

You can use the :headers option to set custom headers:

EnumCSV.csv([[1, 2], [3,"4,5"]], :headers=>['A', 'B']) => "A,B\n1,2\n3,\"4,5\"\n"
EnumCSV.csv([[1, 2], [3,"4,5"]], :headers=>'A,B') => "A,B\n1,2\n3,\"4,5\"\n"

The :file option can be used to output to a file:

EnumCSV.csv([[1, 2]], :file=>'foo.csv') => nil # output written to foo.csv

If a block is passed to the method, all items in the enumerable are yielded to the block, and the block should return an array with the data to use in the CSV output:

EnumCSV.csv([{:a=>1, :b=>2}, {:a=>3, :b=>4}]){|l| [l[:b], l[:a] + 10]} => "2,11\n4,13\n"

License¶ ↑

MIT

Author¶ ↑

Jeremy Evans <code@jeremyevans.net>