Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Turning Excel spreadsheets into hashes

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .rspec
Octocat-spinner-32 README.md
Octocat-spinner-32 Rakefile
Octocat-spinner-32 batch_factory.gemspec
README.md

Batch Factory

Built on top of the roo gem for easy abstraction of Excel and OpenOffice spreadsheets as tabular data input. Assumes the first row to be headings with keys and forms clean Ruby hashmaps for all consecutive rows using cells as values for respective keys.

Uses

Common scenarios include:

  • Batch creates\updates\deletes through an ORM (ActiveRecord, DataMapper, Mongoid, anything that accepts hashes for a given record)

Usage

First,

require 'batch_factory'
hash_worksheet = BatchFactory.from_file 'path/to/some/spreadsheet.xls'

Then, display headings from row 1 that BatchFactory used as hash keys for each row:

hash_worksheet.keys

Show all extracted hashes (one per row starting with row 2):

hash_worksheet.rows

Iterate over it like an array (or enumerable). Or, in fact, any method that either respond to:

hash_worksheet.each do |hash_row|
  puts hash_row.inspect
end

Note: this gem pulls in Activesupport's indefferent access for hashes, so you can access each row's data with Symbols just like Strings. Enjoy.

Installation

gem install batch_factory

Or in a Gemfile if you always want the freshest cut:

gem 'batch_factory', :git => 'git://github.com/jumph4x/batch-factory.git'

Why?

Because the business world still runs on spreadsheets and Excel. This allows executives to effectively interact with your software library or webapp.

Something went wrong with that request. Please try again.