Class: Fixnum
- Inherits:
-
Object
- Object
- Fixnum
- Defined in:
- lib/numbers.rb
Overview
Methods for converting Fixnums between units
Instance Method Summary collapse
-
#gravity_correction ⇒ Float
Gravity correction based on sample temperature.
-
#to_celsius ⇒ Fixnum
Covert Fahrenheit to Celsius.
-
#to_fahrenheit ⇒ Fixnum
Covert Celsius to Fahrenheit.
-
#to_grams ⇒ Float
Covert ounces to grams.
-
#to_kilograms ⇒ Float
Covert pounds to kilograms.
-
#to_liters(unit = :gallons) ⇒ Float
Covert gallons (or quarts) to liters.
-
#to_ounces ⇒ Float
Covert grams to ounces.
-
#to_pounds ⇒ Float
Covert kilograms to pounds.
-
#to_specific_gravity ⇒ Float
Covert Plato to specific gravity.
Instance Method Details
#gravity_correction ⇒ Float
Note:
Temperature must be measured in Celsius
Gravity correction based on sample temperature
94 95 96 97 98 99 100 101 102 |
# File 'lib/numbers.rb', line 94 def gravity_correction if self < 3.98 -0.000032692 * self - 0.000740644 elsif self < 50 -0.0008031922 - 0.0000473773 * self + 0.000007231263 * self * self - 0.00000003078278 * self * self * self else -0.005431719 + 0.0001963596 * self + 0.000002661056 * self * self end end |
#to_celsius ⇒ Fixnum
Covert Fahrenheit to Celsius
20 21 22 |
# File 'lib/numbers.rb', line 20 def to_celsius ((self - 32) / 1.8).round end |
#to_fahrenheit ⇒ Fixnum
Covert Celsius to Fahrenheit
30 31 32 |
# File 'lib/numbers.rb', line 30 def to_fahrenheit ((self * 1.8) + 32).round end |
#to_grams ⇒ Float
Covert ounces to grams
51 52 53 |
# File 'lib/numbers.rb', line 51 def to_grams self.to_f.to_grams end |
#to_kilograms ⇒ Float
Covert pounds to kilograms
71 72 73 |
# File 'lib/numbers.rb', line 71 def to_kilograms self.to_f.to_kilograms end |
#to_liters(unit = :gallons) ⇒ Float
Covert gallons (or quarts) to liters
41 42 43 |
# File 'lib/numbers.rb', line 41 def to_liters unit = :gallons self.to_f.to_liters unit end |
#to_ounces ⇒ Float
Covert grams to ounces
61 62 63 |
# File 'lib/numbers.rb', line 61 def to_ounces self.to_f.to_ounces end |
#to_pounds ⇒ Float
Covert kilograms to pounds
81 82 83 |
# File 'lib/numbers.rb', line 81 def to_pounds self.to_f.to_pounds end |
#to_specific_gravity ⇒ Float
Covert Plato to specific gravity
10 11 12 |
# File 'lib/numbers.rb', line 10 def to_specific_gravity self.to_f.to_specific_gravity end |