Class: Float
- Inherits:
-
Object
- Object
- Float
- Defined in:
- lib/numbers.rb
Overview
Methods for converting Floats between units
Instance Method Summary collapse
-
#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_plato ⇒ Float
Covert specific gravity to Plato.
-
#to_pounds ⇒ Float
Covert kilograms to pounds.
-
#to_specific_gravity ⇒ Float
Covert Plato to specific gravity.
-
#to_temperature_corrected_specific_gravity(temperature, unit = :celsius) ⇒ Float
Covert specific gravity to temperature corrected specific gravity.
Instance Method Details
#to_grams ⇒ Float
Covert ounces to grams
167 168 169 |
# File 'lib/numbers.rb', line 167 def to_grams (self * 28.3495231).round 1 end |
#to_kilograms ⇒ Float
Covert pounds to kilograms
187 188 189 |
# File 'lib/numbers.rb', line 187 def to_kilograms (self * 0.453592).round 1 end |
#to_liters(unit = :gallons) ⇒ Float
Covert gallons (or quarts) to liters
152 153 154 155 156 157 158 159 |
# File 'lib/numbers.rb', line 152 def to_liters unit = :gallons case unit when :gallons (self * 3.785412).round 1 when :quarts (self * 0.946353).round 1 end end |
#to_ounces ⇒ Float
Covert grams to ounces
177 178 179 |
# File 'lib/numbers.rb', line 177 def to_ounces (self * 0.0352739619).round 1 end |
#to_plato ⇒ Float
Covert specific gravity to Plato
115 116 117 |
# File 'lib/numbers.rb', line 115 def to_plato (-676.67 + 1286.4 * self - 800.47 * self * self + 190.74 * self * self * self).round 1 end |
#to_pounds ⇒ Float
Covert kilograms to pounds
197 198 199 |
# File 'lib/numbers.rb', line 197 def to_pounds (self * 2.204623).round 1 end |
#to_specific_gravity ⇒ Float
Covert Plato to specific gravity
125 126 127 |
# File 'lib/numbers.rb', line 125 def to_specific_gravity (self / (258.6 - ((self / 258.2) * 227.1)) + 1.0).round 3 end |
#to_temperature_corrected_specific_gravity(temperature, unit = :celsius) ⇒ Float
Covert specific gravity to temperature corrected specific gravity
138 139 140 141 142 143 |
# File 'lib/numbers.rb', line 138 def to_temperature_corrected_specific_gravity temperature, unit = :celsius temperature = temperature.to_celsius unless unit == :celsius correction = temperature.gravity_correction (self + correction).round 3 end |