RichUnits is simple units system based on Rich Kilmer's original time.rb script, in which different measures of time are represented as seconds via extensions to the Numeric class. Later, Ruby on Rails' ActiveSupport library adopted this script and expanded upon it. RichUnits borrows from their work and a few other renditions this code that have made the rounds to create a robust stand-alone version.
Unique to RichUnits' rendition is the Duration class (inspired by Matthew Harris' version by the same name). Originally time measures were stored as integers representing seconds. The Duration class instead stores the seconds as an attribute and adds an optional segements property which can be used to select exactly how to segment up the time period (years, week, days, etc.).
You only need to require 'richunits' and all of RichUnit's functionality becomes available.
require 'richunits' 2.hours #=> 7200
See RDocs for complete API documentation.
RichUnits utilizes GitHub for development. You will find the git repo under the rubyworks account.
RichUnits utilizes the Syckle build system.
- Copyright (c) 2008 Thomas Sawyer
- Copyright (c) 2006 Matthew Harris
- Copyright (c) 2004 Rich Kilmer
If you have contributed to this code and feel you deserve mention in the copyright notice, please let me know. Since this code has been through a number of hands and other projects (Facets and ActiveSupport among them) it is hard to identify exactly who is responsible for what. Nonetheless, Rich Kilmer is the initiator of the whole idea (AFAIK), so I figure much of the rights belong to him.
RichUnits is distributed under the terms of the MIT license.
See LICENSE.txt file.