Sha256: d4b45b83edbb074c7bb0d03fb5d6c847b6fc281d7726b3dd5b6cb96e589a3262

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

require 'weather_handler/version'
require 'rest-client'
require 'dotenv/load'
require 'json'
require 'retryable'
require 'open_weather_client'
require 'adapters/weather'
require 'decorators/open_weather_response'

module WeatherHandler
  class Weather
    CELSIUM = 'celsium'

    def initialize(city)
      @response = OpenWeatherClient.new(city).call
      @converter = Adapters::Weather
      @kelvin_amount = response.amount_in_kelvins
    end

    def current_temperature(dimension = CELSIUM)
      converter.new(dimension, kelvin_amount).call
    end

    def feels_like_temperature(dimension = CELSIUM)
      amount = (response.parsed_data['feels_like']).round(1)

      converter.new(dimension, amount).call
    end

    def weather_description
      response.parsed_weather_description
    end

    def humidity
      "#{response.parsed_data['humidity']} %"
    end

    def pressure
      "#{response.parsed_data['pressure']} mb"
    end

    private

    attr_reader :response, :converter, :kelvin_amount
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
weather_handler-0.1.2 lib/weather_handler.rb