Coder Social home page Coder Social logo

file_processor's Introduction

FileProcessor

build status Bitdeli Badge

A more powerful CSV file processor

Installation

FileProcessor uses the new CSV library introduced in Ruby 1.9.3, thus it is only compatible with this Ruby version.

Add this line to your application's Gemfile:

gem 'file_processor'

And then execute:

$ bundle

Or install it yourself as:

$ gem install file_processor

Usage

Use it as you would use Ruby's CSV:

FileProcessor::CSV.open(filename, options) do |csv|
  csv.each do |row|
    # process row here
  end
end # automatically closes the file

FileProcessor::CSV is just a wrapper around Ruby's CSV, so you can manipulate it as you would manipulate Ruby's CSV.

You can also use FileProcessor::CSV#process_range to process a range in the file:

FileProcessor::CSV.open(filename, options) do |csv|
  csv.process_range(offset: 2000, limit: 1000) do |row, index|
    # yields 1000 rows starting from line 2000 (i.e., from line 2000 to line 2999)
  end
end # automatically closes the file

Here are the added features:

  • Auto-detect encoding of UTF-8 and ISO-8859-1 (Latin1) files.
  • Auto-detect the column separator (col_sep option) when not given.
  • Skip lines without data when skip_blank is true, which is turned on by default. This means that count will not take these lines into account. Also skips them when iterating through lines.
  • Detects if a file is gzipped, and decompress it for you automatically.

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

file_processor's People

Contributors

vicentemundim avatar

Stargazers

 avatar Uriel Juliatti avatar

Watchers

Marcelo Murad avatar  avatar Rafael Mahler avatar Otávio Cardoso avatar Carlos Figueiredo avatar Gustavo Kloh avatar Tomas Duringer Jacques de Lima avatar

Forkers

isabella232

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.