Class: Fixnum

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

Overview

Methods for converting Fixnums between units

Instance Method Summary collapse

Instance Method Details

#gravity_correctionFloat

Note:

Temperature must be measured in Celsius

Gravity correction based on sample temperature

Examples:

40.gravity_correction

Returns:

  • (Float)

    mass in pounds



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_celsiusFixnum

Covert Fahrenheit to Celsius

Examples:

104.to_celsius

Returns:

  • (Fixnum)

    temperature in Celsius



20
21
22
# File 'lib/numbers.rb', line 20

def to_celsius
  ((self - 32) / 1.8).round
end

#to_fahrenheitFixnum

Covert Celsius to Fahrenheit

Examples:

60.to_fahrenheit

Returns:

  • (Fixnum)

    temperature in Fahrenheit



30
31
32
# File 'lib/numbers.rb', line 30

def to_fahrenheit
  ((self * 1.8) + 32).round
end

#to_gramsFloat

Covert ounces to grams

Examples:

2.to_grams

Returns:

  • (Float)

    mass in grams



51
52
53
# File 'lib/numbers.rb', line 51

def to_grams
  self.to_f.to_grams
end

#to_kilogramsFloat

Covert pounds to kilograms

Examples:

10.to_kilograms

Returns:

  • (Float)

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

Examples:

5.to_liters
15.to_liters :quarts

Returns:

  • (Float)

    volume in liters



41
42
43
# File 'lib/numbers.rb', line 41

def to_liters unit = :gallons
  self.to_f.to_liters unit
end

#to_ouncesFloat

Covert grams to ounces

Examples:

56.to_ounces

Returns:

  • (Float)

    mass in ounces



61
62
63
# File 'lib/numbers.rb', line 61

def to_ounces
  self.to_f.to_ounces
end

#to_poundsFloat

Covert kilograms to pounds

Examples:

10.to_pounds

Returns:

  • (Float)

    mass in pounds



81
82
83
# File 'lib/numbers.rb', line 81

def to_pounds
  self.to_f.to_pounds
end

#to_specific_gravityFloat

Covert Plato to specific gravity

Examples:

14.to_specific_gravity

Returns:

  • (Float)

    degrees Plato



10
11
12
# File 'lib/numbers.rb', line 10

def to_specific_gravity
  self.to_f.to_specific_gravity
end