Herbalist is a natural language measurements parser. It is built on top of the Alchemist gem and draws heavily from the Chronic.
$ sudo gem sources -a http://gemcutter.org $ sudo gem install herbalist
>> require 'herbalist' >> Herbalist.parse("a quarter cup") => #<Alchemist::NumericConversion @value=0.25, @exponent=1.0, @unit_name=:cup> >> Herbalist.parse("it was two and a half football fields") => #<Alchemist::NumericConversion @value=2.5, @exponent=1.0, @unit_name=:football_fields> >> Herbalist.parse('twenty-one and a half Miles') => #<Alchemist::NumericConversion @value=21.5, @exponent=1.0, @unit_name=:miles> >> Herbalist.parse('fifteen kilowatt Hours') => #<Alchemist::NumericConversion @value=15.0, @exponent=1.0, @unit_name=:kilowatt_hours>
Parsing is limited to units that Alchemist can understand.
-Allow parsing of units directly next to digits (ed 4m, 21.5L) -Add options to limit which type of units to parse (only volume or distance)
Copyright © 2009 John Duff. See LICENSE for details.