Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Convert everyday measures into human-grokable units

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 .document
Octocat-spinner-32 .gitignore
Octocat-spinner-32 Gemfile
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.markdown
Octocat-spinner-32 Rakefile
Octocat-spinner-32 co2_equivalents.gemspec
Octocat-spinner-32 rspec.watchr
README.markdown

CO2 Equivalents

co2_equivalents converts CO2 measurements into human-grokable units. For instance, you can convert kilograms of CO2 into "number of cars on the road for a day." It also adds the ability to list out a group of equivalents.

Build Status

Usage

require 'co2_equivalents'

# simple unit conversion
puts CO2Equivalents.grok(2840.7, :cars_driven_for_a_day).to_f
#=> 343.6

# return the default hash of equivalents
puts CO2Equivalents.grok(2840.7).inspect
#=> {
  :light_bulbs_for_a_year: 1234.5,
  :light_bulbs_for_a_day: 454534.5,
  ...
  :cars_driven_for_a_day: 343.6
}

# return a hash of equivalents for the electricity category
puts CO2Equivalents.grok(2840.7, :electricity).inspect
#=> {
  :light_bulbs_for_a_year: 1234.5,
  :light_bulbs_for_a_day: 454534.5,
  ...
}

# defining your own equivalents
class SemiSubmersible < CO2Equivalents::Group
  description 'Conversions for semi-submersible vehicles, such as oil platforms'
  citation 'http://shipinfo.org/index4.htm', :title => 'Ship Information Warehouse Statistics', :author => 'John Doe'

  equivalent :mobile_offshore_drilling_unit_operations_for_a_day, 0.465
  equivalent :mobile_offshore_drilling_unit_operations_for_a_year, 169.725
  equivalent :semi_submersible_crane_vessel_operations_for_a_day, 0.572
  equivalent :semi_submersible_crane_vessel_operations_for_a_year, 208.78
end

You can view the default set of equivalents in lib/co2_equivalents/measurements.

Each equivalence definition means "1 kg of CO2 is equal to X amount of my custom unit," e.g. 1 kg CO2 is equal to 0.465 Mobile Offshore Drilling Unit operations for a day.

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright (c) 2011 Derek Kastner. See LICENSE for details.

Something went wrong with that request. Please try again.