The flight gem is used by Brighter Planet's Carbon Middleware platform to define a mathematical emissions model for a flight on any airline or aircraft. 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.


The flight gem defines a module, BrighterPlanet::Flight 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 FlightRecord < ActiveRecord::Base
  include BrighterPlanet::Flight

f = FlightRecord.new :origin_airport => { :iata_code => 'DTW'}, :destination_airport => { :iata_code => 'SFO' }
# => 2472

Getting Ready for Development

Flight uses bundler to manage dependencies. To prepare your environment, perform the following: git clone git://github.com/brighterplanet/flight.git cd flight 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 flight. 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:

  • flight_emissions.feature, which tests emission values for various inputs
  • flight_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.

See: http://github.com/brighterplanet/sniff


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: http://github.com/brighterplanet/sniff/blob/master/README.markdown

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.