class Numeric
This file extends the Numeric
class to provide simple utility for unit conversions. To properly use these extenstions, default units will/should be used:
> MASS = kilograms¶ ↑
> DISTANCE/MEASUREMENT = meters¶ ↑
> TIME = seconds¶ ↑
> VOLUME = fluid ounces ¶ ↑
So, calling 3.pounds will return 1.36077711, which is the value converted to the base unit of kilograms.
When retrieving the values, you can call one of the to(unit) methods.
> 5.km.to(:miles) -> 3.10685596118667¶ ↑
whereas
> 5.km -> 5000 (meters)¶ ↑
Public Instance Methods
centimeters()
click to toggle source
# File lib/numeric/numeric_units.rb, line 64 def centimeters self * 0.01.meters end
Also aliased as: cm, centimeter
cup()
click to toggle source
# File lib/numeric/numeric_units.rb, line 145 def cup self * 8.fl_oz end
Also aliased as: cups
feet()
click to toggle source
# File lib/numeric/numeric_units.rb, line 70 def feet self * 0.3048.meters end
fluid_ounce()
click to toggle source
VOLUME #####
# File lib/numeric/numeric_units.rb, line 127 def fluid_ounce self end
Also aliased as: fluid_ounces, fl_oz
hours()
click to toggle source
# File lib/numeric/numeric_units.rb, line 117 def hours self * 60.minutes end
inches()
click to toggle source
# File lib/numeric/numeric_units.rb, line 76 def inches self * 0.0254.meters end
kilograms()
click to toggle source
MASS #####
# File lib/numeric/numeric_units.rb, line 19 def kilograms self end
kilometers()
click to toggle source
# File lib/numeric/numeric_units.rb, line 94 def kilometers self * 1000.meters end
meters()
click to toggle source
DISTANCE/MEASUREMENTS/LENGTH #####
# File lib/numeric/numeric_units.rb, line 52 def meters self end
miles()
click to toggle source
# File lib/numeric/numeric_units.rb, line 88 def miles self * 1609.344.meters end
millimeters()
click to toggle source
# File lib/numeric/numeric_units.rb, line 58 def millimeters self * 0.001.meters end
Also aliased as: mm, millimeter
minutes()
click to toggle source
# File lib/numeric/numeric_units.rb, line 110 def minutes self * 60.seconds end
ounce()
click to toggle source
# File lib/numeric/numeric_units.rb, line 33 def ounce self * 0.0283495231.kilograms end
pint()
click to toggle source
# File lib/numeric/numeric_units.rb, line 150 def pint self * 16.fl_oz end
pounds()
click to toggle source
# File lib/numeric/numeric_units.rb, line 26 def pounds self * 0.45359237.kilograms end
quart()
click to toggle source
# File lib/numeric/numeric_units.rb, line 156 def quart self * 16.fl_oz end
seconds()
click to toggle source
TIME ####
# File lib/numeric/numeric_units.rb, line 103 def seconds self end
stone()
click to toggle source
# File lib/numeric/numeric_units.rb, line 39 def stone self * 6.35029318.kilograms end
Also aliased as: stones
tablespoon()
click to toggle source
# File lib/numeric/numeric_units.rb, line 139 def tablespoon self * 0.5.fl_oz end
Also aliased as: tablespoons, tbsp
teaspoon()
click to toggle source
# File lib/numeric/numeric_units.rb, line 133 def teaspoon self * (1.0/6.0) end
to(unit)
click to toggle source
Call using something like to(:pounds)
# File lib/numeric/numeric_units.rb, line 163 def to(unit) self / 1.send(unit) end
ton()
click to toggle source
# File lib/numeric/numeric_units.rb, line 44 def ton self * 907.18474.kilograms end
Also aliased as: tons
yards()
click to toggle source
# File lib/numeric/numeric_units.rb, line 82 def yards self * 3.feet end