Boundy is a bounding and constraining library for any comparable types; it is like Ranges, but with much more flexibility. Boundy allows for the creation of bounded and partially-bounded intervals -- or domains. Boundy allows for these domains to be intersected, creating a new domain, which can be acted on further. I originally wrote Boundy for intersecting date ranges for reporting, but it should be useable for any Comparable types.
Gemfile gem 'boundy', '~> 0.3.0'
install gem install boundy