Class: Float

Inherits:
Object
  • Object
show all
Defined in:
lib/numbers.rb

Overview

Methods for converting Floats between units

Instance Method Summary collapse

Instance Method Details

#to_gramsFloat

Covert ounces to grams

Examples:

5.5.to_grams

Returns:

  • (Float)

    mass in grams



167
168
169
# File 'lib/numbers.rb', line 167

def to_grams
  (self * 28.3495231).round 1
end

#to_kilogramsFloat

Covert pounds to kilograms

Examples:

15.5.to_kilograms

Returns:

  • (Float)

    mass in 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

Examples:

5.to_liters
15.to_liters :quarts

Returns:

  • (Float)

    volume in 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_ouncesFloat

Covert grams to ounces

Examples:

100.5.to_ounces

Returns:

  • (Float)

    mass in ounces



177
178
179
# File 'lib/numbers.rb', line 177

def to_ounces
  (self * 0.0352739619).round 1
end

#to_platoFloat

Covert specific gravity to Plato

Examples:

1.055.to_plato

Returns:

  • (Float)

    degrees 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_poundsFloat

Covert kilograms to pounds

Examples:

7.5.to_pounds

Returns:

  • (Float)

    mass in pounds



197
198
199
# File 'lib/numbers.rb', line 197

def to_pounds
  (self * 2.204623).round 1
end

#to_specific_gravityFloat

Covert Plato to specific gravity

Examples:

13.6.to_specific_gravity

Returns:

  • (Float)

    degrees Plato



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

Examples:

1.055.to_temperature_corrected_specific_gravity 40
1.055.to_temperature_corrected_specific_gravity 110, :fahrenheit

Parameters:

  • temperature (Fixnum)

    temperature of sample

  • unit (Symbol) (defaults to: :celsius)

    unit of temperature used; :celsius or :fahrenheit

Returns:

  • (Float)

    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