Project

csv_parser

0.0
No commit activity in last 3 years
No release in over 3 years
CSV parser with advanced error reporting
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.3
>= 0

Runtime

 Project Readme

CsvParser

CsvParser is a CSV parser that focuses on identifying errors.

Installation

Add this line to your application's Gemfile:

gem 'csv_parser'

And then execute:

$ bundle

Or install it yourself as:

$ gem install csv_parser

Usage

CsvParser's goal is to give you descriptive error messages.

Error types

  • missing closing quote (CsvParser::MissingQuoteError)
  • quote in the wrong place (CsvParser::StrayQuoteError)
  • rows with not enough fields (CsvParser::MissingFieldsError)
  • rows with too many fields (CsvParser::ExtraFieldsError)

Options

You can pass in an options hash to the CsvParser.parse method that contains one or more of the following options:

  • :field_sep - specify field separator (default is ",")
  • :record_sep - specify record separator (default is "\n")
  • :quote_char - specify quote character (default is "\"")
  • :allow_empty_record - specify whether empty records are allowed (default is true)
  • :skip_empty_record - specify whether empty records are skipped (default is true)
  • :allow_uneven_records - specify whether records with different field lengths are allowed (default is true)

Example

require 'csv_parser'

data = <<EOF
foo,"bar
baz,quz
EOF
begin
  result = CsvParser.parse(data)
rescue CsvParser::Error => e
  # e is a CsvParser::MissingQuoteError
end

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