Class: TempConverterGem::Convert
- Inherits:
-
Object
- Object
- TempConverterGem::Convert
- Defined in:
- lib/temp_converter_gem.rb
Class Method Summary collapse
- .to_celsius(scale, temp) ⇒ Object
- .to_fahrenheit(scale, temp) ⇒ Object
- .to_kelvin(scale, temp) ⇒ Object
Class Method Details
.to_celsius(scale, temp) ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/temp_converter_gem.rb', line 8 def to_celsius(scale, temp) case scale when :fahrenheit, :f return (temp - 32) / 1.8 when :kelvin, :k return (temp - 273.15) else raise ArgumentError, "Invalid scale" end end |
.to_fahrenheit(scale, temp) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/temp_converter_gem.rb', line 19 def to_fahrenheit(scale, temp) case scale when :celsius, :c return (temp * 1.8) + 32 when :kelvin, :k return ((temp - 273.15) * 1.8) + 32 else raise ArgumentError, "Invalid scale" end end |
.to_kelvin(scale, temp) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/temp_converter_gem.rb', line 30 def to_kelvin(scale, temp) case scale when :fahrenheit, :f return temp + 273.15 when :celsius, :c return ((temp - 32) / 1.8) + 273.15 else raise ArgumentError, "Invalid scale" end end |