Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time


The purchase gem is used by Brighter Planet's Carbon Middleware platform to define a mathematical emissions model for a purchase activity. In addition, this gem defines how the model's calculation is displayed in a human readable format.

Contributions are welcome and encouraged, as we believe that help from the scientific and developer communities will help us provide correct and transparent models of greenhouse gas-emitting activities. See the section on the Collaboration Cycle below.

Build Status


The purchase gem defines a module, BrighterPlanet::Purchase that should be included into an ActiveRecord model. Calling #emission on an instance of the model will determine the amount of emissions (CO2e) generated by the activity.

class PurchaseRecord < ActiveRecord::Base
  include BrighterPlanet::Purchase

p = :merchant_category_code => 2324, :amount => 873.45
# => 2472

Getting Ready for Development

Purchase uses bundler to manage dependencies. To prepare your environment, perform the following: git clone git:// cd purchase gem install bundler (note: prior to bundler 1.0 release, add --pre) bundle install

A Note to RVM Users (and Non-Users)

RVM is a great tool for testing and development as it can create independent gem environments.

Included in the repository is a .rvmrc that will automatically create a ruby 1.8.7 gemset for you named purchase. If you already have a gemset with the same name, simply replace the `pwd` within the .rvmrc to whatever name you want.


Our goal is to have sufficient testing coverage for our emissions models. We have chosen to write our tests using cucumber as the table-formatted testing fits well with our calculations tests and the plain-english stories lower the barrier to entry for programmers of all skill levels.

There are two main features:

  • purchase_emissions.feature, which tests emission values for various inputs
  • purchase_committees.feature, which tests sub-calculations used within the model

To run all tests: rake or cucumber

To run individual tests: cucumber features/name_of_feature.feature

To run a specific scenario: cucumber features/name_of_feature.feature:line_number_of_scenario


The sniff gem is used to provide a testing environment that loads dependent data models (defined in the earth gem), a database, and testing fixtures.



The earth gem contains the model definitions for dependent data models. For instance, this is zip code data or fuel prices used in the emissions calculations. Earth will look for any test fixtures defined in lib/test_support/db/fixtures. These sample records are in csv format and are imported into the testing database.


See the README for the sniff gem:

Collaboration cycle

Brighter Planet vigorously encourages collaborative improvement of its emitter libraries. Collaboration requires a (free) GitHub account.


  1. Fork the emitter repository on GitHub.
  2. Write a test proving the existing implementation's inadequacy. Ensure that the test fails. Commit the test.
  3. Improve the code until your new test passes and commit your changes.
  4. Push your changes to your GitHub fork.
  5. Submit a pull request to brighterplanet.

Brighter Planet

  1. Receive a pull request.
  2. Pull changes from forked repository.
  3. Ensure tests pass.
  4. Review changes for scientific accuracy.
  5. Merge changes to master repository and publish.
  6. Direct production environment to use new emitter version.


Copyright © 2010 Brighter Planet. See LICENSE for details. Contact Brighter Planet for dual-license arrangements.


No description, website, or topics provided.




No packages published

Contributors 4