class Adapters::Weather
Constants
- CELSIUM
- CONVERTATION_FAHRENHEIT_VALUE
- CONVERTATION_KELVIN_VALUE
- ERROR_MESSAGE
- FAHRENHEIT
- FAHRENHEIT_COEFFICIENT
- KELVIN
Attributes
amount[R]
dimension[R]
standard_amount[R]
Public Class Methods
new(dimension, standard_amount)
click to toggle source
# File lib/adapters/weather.rb, line 13 def initialize(dimension, standard_amount) @dimension = dimension @standard_amount = standard_amount end
Public Instance Methods
call()
click to toggle source
# File lib/adapters/weather.rb, line 18 def call converter(dimension, standard_amount) end
Private Instance Methods
converter(dimension, quantity)
click to toggle source
# File lib/adapters/weather.rb, line 26 def converter(dimension, quantity) case dimension.downcase when CELSIUM "#{degrees_to_c(quantity)} C" when KELVIN "#{quantity} K" when FAHRENHEIT "#{degrees_to_f(quantity)} F" else ERROR_MESSAGE end end
degrees_to_c(quantity)
click to toggle source
# File lib/adapters/weather.rb, line 39 def degrees_to_c(quantity) (quantity - CONVERTATION_KELVIN_VALUE).round(1) end
degrees_to_f(quantity)
click to toggle source
# File lib/adapters/weather.rb, line 43 def degrees_to_f(quantity) (quantity * FAHRENHEIT_COEFFICIENT - CONVERTATION_FAHRENHEIT_VALUE).round(1) end