Units.create :length do |m| m.system :english do |s| s.unit :name => :inch, :plural => :inches, :abbrev => :in s.unit :name => :foot, :plural => :feet, :equals => 12.inches, :abbrev => :ft s.unit :name => :yard, :equals => 3.feet, :abbrev => :yd s.unit :name => :mile, :equals => 5280.feet, :abbrev => :mi s.unit :name => :nautical_mile, :equals => 1852.meters, :abbrev => :nmi s.format :name => :feet_inches_and_32s, :format => lambda { |u| ru = u.round_to_nearest(1.inch,32) feet = ru.feet.floor inches = (ru-feet).inches "#{feet} #{inches.with_fraction 32}" } end m.system :old_english do |s| s.unit :name => :fathom, :equals => 2.yards s.unit :name => :chain, :equals => 22.yards s.unit :name => :furlong, :equals => 660.feet s.unit :name => :league, :equals => 3.nmi end m.system :metric do |s| s.unit :name => :meter, :equals =>39.37.inches, :abbrev => :m, :greek => :ten s.unit :name => :anstrom, :equals => 0.1.nanometers, :abbrev => :A end m.system :astronomical do |s| s.unit :name => :astronomical_unit, :equals => 149598000.kilometers, :abbrev => :AU s.unit :name => :light_year, :equals => speed_of_light*(year.seconds), :abbrev => :ly s.unit :name => :parsec, :equals => 3.262.light_years, :abbrev => :pc end end