No commit activity in last 3 years
No release in over 3 years
Detect separators in CSV content
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.13
~> 10.0
~> 3.0
 Project Readme

CsvSeparatorDetector

travis

Installation

Add this line to your application's Gemfile:

gem 'csv_separator_detector'

And then execute:

$ bundle

Or install it yourself as:

$ gem install csv_separator_detector

Usage

begin
  content = File.read('/path/to/csv.file')
  separator = CsvSeparatorDetector.new(content).call # => ';'
rescue CsvSeparatorDetector::Error
  # we couldn't reliably determine separator.
end

Explanation

This class knows a few common csv delimiters and tries to parse given content using them (by passing each delimiter as col_sep option to CSV from stdlib). Then it tries to make sense of the result. All rows turned out to be just one column wide? That's likely because we used comma separator and the file is tab-delimited.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/stulentsev/csv_separator_detector.