Sha256: 1e39d9b29b40271661641a6ad4a2166a8065776a06c57cb3dcebdaf862d56760
Contents?: true
Size: 1.11 KB
Versions: 1
Compression:
Stored size: 1.11 KB
Contents
# frozen_string_literal: true module Adapters class Weather CONVERTATION_KELVIN_VALUE = 273.15 CONVERTATION_FAHRENHEIT_VALUE = 459.67 FAHRENHEIT_COEFFICIENT = 1.8 CELSIUM = 'celsium' KELVIN = 'kelvin' FAHRENHEIT = 'fahrenheit' ERROR_MESSAGE = 'Please, try to type correct dimension. Correct types are: Celsium, Kelvin and Fahrenheit.' def initialize(dimension, standard_amount) @dimension = dimension @standard_amount = standard_amount end def call converter(dimension, standard_amount) end private attr_reader :standard_amount, :dimension, :amount 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 def degrees_to_c(quantity) (quantity - CONVERTATION_KELVIN_VALUE).round(1) end def degrees_to_f(quantity) (quantity * FAHRENHEIT_COEFFICIENT - CONVERTATION_FAHRENHEIT_VALUE).round(1) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
weather_handler-0.1.2 | lib/adapters/weather.rb |