class ConvertTemp
Constants
- FAHRENHEIT_OFFSET
- FAHRENHEIT_S
- KELVIN_SHIFT
Attributes
current_unit[RW]
temperature[RW]
Public Class Methods
new(temperature, current_unit = 'celsius')
click to toggle source
# File lib/unit.rb, line 10 def initialize(temperature, current_unit = 'celsius') @temperature = temperature @current_unit = current_unit end
Public Instance Methods
case_celsius()
click to toggle source
# File lib/unit.rb, line 26 def case_celsius case @unit when 'fahrenheit' @temperature = (temperature * FAHRENHEIT_S) + FAHRENHEIT_OFFSET when 'kelvin' @temperature = temperature + KELVIN_SHIFT else @temperature end end
case_fahrenheit()
click to toggle source
# File lib/unit.rb, line 37 def case_fahrenheit case @unit when 'celsius' @temperature = fahrenheit_to_celcius when 'kelvin' @temperature = fahrenheit_to_celcius + KELVIN_SHIFT else @temperature end end
case_kelvin()
click to toggle source
# File lib/unit.rb, line 47 def case_kelvin case @unit when 'fahrenheit' @temperature = (kelvin_to_celcius * FAHRENHEIT_S) + FAHRENHEIT_OFFSET when 'celsius' @temperature = kelvin_to_celcius else @temperature end end
conv(unit)
click to toggle source
# File lib/unit.rb, line 15 def conv(unit) @unit = unit if @current_unit == 'celsius' case_celsius elsif @current_unit == 'fahrenheit' case_fahrenheit elsif @current_unit == 'kelvin' case_kelvin end end
fahrenheit_to_celcius()
click to toggle source
# File lib/unit.rb, line 57 def fahrenheit_to_celcius @temperature = (temperature - FAHRENHEIT_OFFSET) / FAHRENHEIT_S end
kelvin_to_celcius()
click to toggle source
# File lib/unit.rb, line 61 def kelvin_to_celcius @temperature = temperature - KELVIN_SHIFT end