Dreader

A simple DSL built on top of roo to read and process tabular data (CSV, LibreOffice, Excel).

Use this gem to specify the structure of some tabular data you want to process. The input data can be in CSV, LibreOffice, and Excel. Each row can then be passed to a block of code you define.

The gem can thus be used to check, process, import data. We use it to import data into Rails application, but the gem can used in any Ruby application.

The gem should be relatively easy to use, despite its name: dread stands for *d*ata *r*eader.

The gem depends on roo.

Installation

Add this line to your application's Gemfile:

gem 'dreader'

And then execute:

$ bundle

Or install it yourself as:

$ gem install dreader

Usage

i = Dreader::Engine.new

i.options do
  start_at 1
end

# first column is called name
# :name should be non nil and of length greater than 0
i.column :name do
  check do |x|
    x and x.length > 0
  end
end

# second column is called surname
# :surname should be non nil and of length greater than 0
i.column :surname do
  check do |x|
    x and x.length > 0
  end
end

# third column is called birthdate
# :name should be non nil and of length greater than 0
i.column :birthdate do
  check do |x|
    x.class == Date
  end
end

# fourth column is called age
# we make it into an integer
# age should be greater than 0
i.column :age do
  process do |r|
    r.to_i
  end

  check do |r|
    r > 0
  end
end

# when we decide to process the file, for every row
# we print the value of the name and the value of the surname
i.mapping do |r|
  puts "#{r[:name][:value]} #{r[:surname][:value]}"
end

i.read "/home/adolfo/Desktop/a.ods"
i.process

Known Bugs and Limitations

No known bugs and an unknown number of unknown bugs.

(See the open issues for the known bugs.)

Development

After checking out the repo, run bin/setup to install dependencies. 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.

Contributing

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

License

The gem is available as open source under the terms of the MIT License.