CSV++
CSV++ takes a <DELIMITER>
separated input file and a JSON format specification
and turns it into Ruby Objects. See test/sample_inputs/simple.txt
and
test/sample_formats/simple.json
for example.
Installation
Add this line to your application's Gemfile:
gem 'csvpp'
And then execute:
$ bundle
Or install it yourself as:
$ gem install csvpp
For development of CSV++
First make sure that you have bundler and the Ruby version installed that is
specified in .ruby-version
. Then run:
$ bundle
Usage
CSVPP.parse(
input: 'test/sample_inputs/simple.txt',
format: 'test/sample_formats/simple.json'
) # => [{"v1"=>34, "line_number"=>1, "v2"=>"foobar"}, {"v1"=>99, "line_number"=>2, "v2"=>"hi there"}]
CLI
CSV++ comes with a CLI that speaks with the Formats API.
To print a list of known formats run:
$ csvpp formats
The parse
command can be used to parse an input file with a given format,
either fetched from the API or from a local JSON specification file.
For example, to import some REKOLE cost data to a local sqlite DB for querying, run:
$ csvpp parse --format fk_2017 --output costs.db test/sample_inputs/fk_2017.txt
Run csvpp help parse
for more details.
Development
After checking out the repo, run bin/setup
to install dependencies. Then, run
rake test
to run the tests. You can also run bin/console
for an interactive
prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To
release a new version, update the version number in version.rb
, and then run
bundle exec rake release
, which will create a git tag for the version, push
git commits and tags, and push the .gem
file to
rubygems.org.
License
The gem is available as open source under the terms of the MIT License.