class Converter

Convert temperature in fahrenheit or kelvin to degrees celcius @example

converter = Converter.new
args = { unit: 'fahrenheit', value: 1.8 }
@range = converter.range_to_celcius(args) / 2.0
args[:value] = 21
@wanted_value = converter.temp_to_celcius(args)

Public Instance Methods

range_to_celcius(args) click to toggle source

If range not in celcius, it will be converted into celcius @param args [Hash] @option args [Numeric] :value the given range @option args [String] :unit the unit of the range

# 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) click to toggle source

Convert value from fahrenheit to celcius @param value [Numeric] the value that should be converted @return [Numeric] return the temperature in celcius

# File lib/converter.rb, line 42
def temp_fahrenheit(value)
  (value - 32) / 1.8
end
temp_kelvin(value) click to toggle source

Convert value from kelvin to celcius @param value [Numeric] the value that should be converted @return [Numeric] return the temperature in celcius

# File lib/converter.rb, line 50
def temp_kelvin(value)
  value - 273.15
end
temp_to_celcius(args) click to toggle source

If temperature is not in celcius, it will be converted into celcius @param args [Hash] @option args [Numeric] :value the given temperature @option args [String] :unit the unit of the temperature

# 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