Class: Temperature
- Inherits:
-
Object
- Object
- Temperature
- Defined in:
- lib/temperature.rb
Overview
Temperature type with unit convertion methods
The Temperature class accepts any temperature value in degrees celsius and can convert it to any other unit with helper methods
Constant Summary collapse
- KELVIN_SHIFT =
273.15
- FAHRENHEIT_OFFSET =
32
- FAHRENHEIT_SLOPE =
Rational(9,5)
Instance Attribute Summary collapse
-
#temperature ⇒ Object
readonly
Returns the value of attribute temperature.
Instance Method Summary collapse
-
#initialize(temperature) ⇒ Temperature
constructor
A new instance of Temperature.
-
#to_celsius ⇒ Number
Return the temperature value in degrees celsius.
- #to_fahrenheit ⇒ Object
- #to_kelvin ⇒ Object
Constructor Details
#initialize(temperature) ⇒ Temperature
Returns a new instance of Temperature.
16 17 18 |
# File 'lib/temperature.rb', line 16 def initialize temperature @temperature = temperature end |
Instance Attribute Details
#temperature ⇒ Object (readonly)
Returns the value of attribute temperature.
9 10 11 |
# File 'lib/temperature.rb', line 9 def temperature @temperature end |
Instance Method Details
#to_celsius ⇒ Number
Return the temperature value in degrees celsius
25 26 27 |
# File 'lib/temperature.rb', line 25 def to_celsius temperature end |
#to_fahrenheit ⇒ Object
29 30 31 |
# File 'lib/temperature.rb', line 29 def to_fahrenheit (to_celsius * FAHRENHEIT_SLOPE) + FAHRENHEIT_OFFSET end |
#to_kelvin ⇒ Object
33 34 35 |
# File 'lib/temperature.rb', line 33 def to_kelvin to_celsius + KELVIN_SHIFT end |