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

centimeter()
Alias for: centimeters
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
cm()
Alias for: centimeters
cup() click to toggle source
# File lib/numeric/numeric_units.rb, line 145
def cup
  self * 8.fl_oz
end
Also aliased as: cups
cups()
Alias for: cup
feet() click to toggle source
# File lib/numeric/numeric_units.rb, line 70
def feet
  self * 0.3048.meters
end
Also aliased as: ft, foot
fl_oz()
Alias for: fluid_ounce
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
fluid_ounces()
Alias for: fluid_ounce
foot()
Alias for: feet
ft()
Alias for: feet
hour()
Alias for: hours
hours() click to toggle source
# File lib/numeric/numeric_units.rb, line 117
def hours
  self * 60.minutes
end
Also aliased as: hr, hrs, hour
hr()
Alias for: hours
hrs()
Alias for: hours
in()
Alias for: inches
inch()
Alias for: inches
inches() click to toggle source
# File lib/numeric/numeric_units.rb, line 76
def inches
  self * 0.0254.meters
end
Also aliased as: in, inch
kg()
Alias for: kilograms
kgs()
Alias for: kilograms
kilogram()
Alias for: kilograms
kilograms() click to toggle source

MASS #####

# File lib/numeric/numeric_units.rb, line 19
def kilograms
  self
end
Also aliased as: kilogram, kg, kgs
kilometer()
Alias for: kilometers
kilometers() click to toggle source
# File lib/numeric/numeric_units.rb, line 94
def kilometers
  self * 1000.meters
end
Also aliased as: km, kilometer
km()
Alias for: kilometers
lb()
Alias for: pounds
lbs()
Alias for: pounds
m()
Alias for: meters
meter()
Alias for: meters
meters() click to toggle source

DISTANCE/MEASUREMENTS/LENGTH #####

# File lib/numeric/numeric_units.rb, line 52
def meters
  self
end
Also aliased as: m, meter
mi()
Alias for: miles
mile()
Alias for: miles
miles() click to toggle source
# File lib/numeric/numeric_units.rb, line 88
def miles
  self * 1609.344.meters
end
Also aliased as: mi, mile
millimeter()
Alias for: millimeters
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
min()
Alias for: minutes
mins()
Alias for: minutes
minute()
Alias for: minutes
minutes() click to toggle source
# File lib/numeric/numeric_units.rb, line 110
def minutes
  self * 60.seconds
end
Also aliased as: min, minute, mins
mm()
Alias for: millimeters
ounce() click to toggle source
# File lib/numeric/numeric_units.rb, line 33
def ounce
  self * 0.0283495231.kilograms
end
Also aliased as: oz, ounces
ounces()
Alias for: ounce
oz()
Alias for: ounce
pint() click to toggle source
# File lib/numeric/numeric_units.rb, line 150
def pint
  self * 16.fl_oz
end
Also aliased as: pints, pt
pints()
Alias for: pint
pound()
Alias for: pounds
pounds() click to toggle source
# File lib/numeric/numeric_units.rb, line 26
def pounds
  self * 0.45359237.kilograms
end
Also aliased as: pound, lb, lbs
pt()
Alias for: pint
qt()
Alias for: quart
quart() click to toggle source
# File lib/numeric/numeric_units.rb, line 156
def quart
  self * 16.fl_oz
end
Also aliased as: quarts, qt
quarts()
Alias for: quart
sec()
Alias for: seconds
second()
Alias for: seconds
seconds() click to toggle source

TIME ####

# File lib/numeric/numeric_units.rb, line 103
def seconds
  self
end
Also aliased as: second, secs, sec
secs()
Alias for: seconds
stone() click to toggle source
# File lib/numeric/numeric_units.rb, line 39
def stone
  self * 6.35029318.kilograms
end
Also aliased as: stones
stones()
Alias for: stone
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
tablespoons()
Alias for: tablespoon
tbsp()
Alias for: tablespoon
teaspoon() click to toggle source
# File lib/numeric/numeric_units.rb, line 133
def teaspoon
  self * (1.0/6.0)
end
Also aliased as: teaspoons, tsp
teaspoons()
Alias for: teaspoon
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
tons()
Alias for: ton
tsp()
Alias for: teaspoon
yard()
Alias for: yards
yards() click to toggle source
# File lib/numeric/numeric_units.rb, line 82
def yards
  self * 3.feet
end
Also aliased as: yd, yard
yd()
Alias for: yards