Class: M9t::Temperature
Overview
Represents a temperature Using degrees (celcius), not kelvin, as default unit
Constant Summary collapse
- DEFAULT_OPTIONS =
{ units: :degrees, abbreviated: false, precision: 5 }
- CONVERSIONS =
{ degrees: 1.0, kelvin: nil, fahrenheit: nil }
- ABSOLUTE_ZERO =
Conversions
-273.15
Instance Attribute Summary
Attributes included from Base
Class Method Summary collapse
- .fahrenheit(fahrenheit) ⇒ Object
-
.fahrenheit_to_degrees(fahrenheit) ⇒ Object
Converts Fahrenheit to degrees.
-
.kelvin(kelvin) ⇒ Object
Accepts a value in kelvin and returns the equivalent M9t::Temperature.
-
.kelvin_to_degrees(kelvin) ⇒ Object
Converts kelvin to degrees.
-
.to_fahrenheit(degrees) ⇒ Object
Converts degrees to Fahrenheit.
-
.to_kelvin(degrees) ⇒ Object
Converts degrees to kelvin.
Instance Method Summary collapse
- #to_fahrenheit ⇒ Object
-
#to_kelvin ⇒ Object
Returns the value converted to kilometers.
Methods included from Base
add_options, generate_conversions, included, #initialize, #method_missing, #respond_to?, #to_s
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class M9t::Base
Class Method Details
.fahrenheit(fahrenheit) ⇒ Object
27 28 29 |
# File 'lib/m9t/temperature.rb', line 27 def fahrenheit(fahrenheit) new(fahrenheit_to_degrees(fahrenheit)) end |
.fahrenheit_to_degrees(fahrenheit) ⇒ Object
Converts Fahrenheit to degrees
47 48 49 |
# File 'lib/m9t/temperature.rb', line 47 def fahrenheit_to_degrees(fahrenheit) (fahrenheit.to_f - 32) * 5.0 / 9.0 end |
.kelvin(kelvin) ⇒ Object
Accepts a value in kelvin and returns the equivalent M9t::Temperature
23 24 25 |
# File 'lib/m9t/temperature.rb', line 23 def kelvin(kelvin) new(kelvin.to_f + ABSOLUTE_ZERO) end |
.kelvin_to_degrees(kelvin) ⇒ Object
Converts kelvin to degrees
42 43 44 |
# File 'lib/m9t/temperature.rb', line 42 def kelvin_to_degrees(kelvin) kelvin.to_f + ABSOLUTE_ZERO end |
.to_fahrenheit(degrees) ⇒ Object
Converts degrees to Fahrenheit
37 38 39 |
# File 'lib/m9t/temperature.rb', line 37 def to_fahrenheit(degrees) degrees.to_f * 9.0 / 5.0 + 32 end |
.to_kelvin(degrees) ⇒ Object
Converts degrees to kelvin
32 33 34 |
# File 'lib/m9t/temperature.rb', line 32 def to_kelvin(degrees) degrees.to_f - ABSOLUTE_ZERO end |
Instance Method Details
#to_fahrenheit ⇒ Object
59 60 61 |
# File 'lib/m9t/temperature.rb', line 59 def to_fahrenheit self.class.to_fahrenheit(@value) end |
#to_kelvin ⇒ Object
Returns the value converted to kilometers
55 56 57 |
# File 'lib/m9t/temperature.rb', line 55 def to_kelvin self.class.to_kelvin(@value) end |