Class: Converter
- Inherits:
-
Object
- Object
- Converter
- Defined in:
- lib/converter.rb
Overview
Convert temperature in fahrenheit or kelvin to degrees celcius
Instance Method Summary collapse
-
#range_to_celcius(args) ⇒ Object
If range not in celcius, it will be converted into celcius.
-
#temp_fahrenheit(value) ⇒ Numeric
Convert value from fahrenheit to celcius.
-
#temp_kelvin(value) ⇒ Numeric
Convert value from kelvin to celcius.
-
#temp_to_celcius(args) ⇒ Object
If temperature is not in celcius, it will be converted into celcius.
Instance Method Details
#range_to_celcius(args) ⇒ Object
If range not in celcius, it will be converted into celcius
15 16 17 18 19 20 21 |
# File 'lib/converter.rb', line 15 def range_to_celcius(args) tempo = if args[:unit] == 'fahrenheit' args[:value] / 1.8 else args[:value] end end |
#temp_fahrenheit(value) ⇒ Numeric
Convert value from fahrenheit to celcius
42 43 44 |
# File 'lib/converter.rb', line 42 def temp_fahrenheit(value) (value - 32) / 1.8 end |
#temp_kelvin(value) ⇒ Numeric
Convert value from kelvin to celcius
50 51 52 |
# File 'lib/converter.rb', line 50 def temp_kelvin(value) value - 273.15 end |
#temp_to_celcius(args) ⇒ Object
If temperature is not in celcius, it will be converted into celcius
28 29 30 31 32 33 34 35 36 |
# File 'lib/converter.rb', line 28 def temp_to_celcius(args) tempo = if args[:unit] == 'fahrenheit' temp_fahrenheit(args[:value]) elsif args[:unit] == 'kelvin' temp_kelvin(args[:value]) else args[:value] end end |