Temperature.rb released

As I’ve been working on my weather station at home at nights, I realized the code would be a lot cleaner if I wasn’t constantly keeping track of temperature units.  So I created the Temperature module for Ruby which adds methods to numbers to make them implicitly temperatures, as well as a parsing method on strings.  To get a flavor of it, here are some examples:

freezing_in_F = 32
freezing_in_C = freezing_in_F.to_C

boiling_in_C = 100
boiling_in_C.units = "C"
boiling_in_F = boiling_in_C.to_F

absolute_zero = "0K".to_degrees
absolute_zero_in_C = absolute_zero.to_C
absolute_zero_in_F = absolute_zero.to_F

The full documentation for the project is on rubyforge.  Gems, tar, and zip format have all been published, and it should be propagating out to the main gem servers tonight.  It’s not exceptionally complicated, however it is convenient, and it’s even got 236 unit tests to ensure it’s doing things right.  The code is released under the MIT license, so you are pretty much able to do anything you want with it.

2 thoughts on “Temperature.rb released”

  1. FYI, the ‘ruby-units’ gem does a pretty reasonable job of temperature unit conversions. You can also use it for complex unit math and equations where the values have units.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s