Class: Weather
- Inherits:
-
Object
- Object
- Weather
- Defined in:
- lib/easy_weather/weather.rb
Constant Summary collapse
- BASE_URL =
"https://api.openweathermap.org/data/2.5/"
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#forecast ⇒ Object
Returns the value of attribute forecast.
Instance Method Summary collapse
- #astronomy_data ⇒ Object
- #atmosphere_data ⇒ Object
- #forecast_data ⇒ Object
-
#initialize(city) ⇒ Weather
constructor
A new instance of Weather.
- #temperature ⇒ Object
- #wind ⇒ Object
Constructor Details
#initialize(city) ⇒ Weather
Returns a new instance of Weather.
8 9 10 11 |
# File 'lib/easy_weather/weather.rb', line 8 def initialize(city) @data = get_general_data(city) @forecast = get_forecast_data(5, city) end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'lib/easy_weather/weather.rb', line 6 def data @data end |
#forecast ⇒ Object
Returns the value of attribute forecast.
6 7 8 |
# File 'lib/easy_weather/weather.rb', line 6 def forecast @forecast end |
Instance Method Details
#astronomy_data ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/easy_weather/weather.rb', line 22 def astronomy_data data_hash = { sunrise: data["sys"]["sunrise"], sunset: data["sys"]["sunset"] } "Sunrice: #{data_hash[:sunrise]} UTC, sunset: #{data_hash[:sunset]} UTC" end |
#atmosphere_data ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/easy_weather/weather.rb', line 38 def atmosphere_data data_hash = { humidity: data["main"]["humidity"], pressure: data["main"]["pressure"], visibility: data["visibility"] } "Humidy: #{data_hash[:humidity]}%, pressure: #{data_hash[:pressure]}hPa, visibility: #{data_hash[:visibility]} meters" end |
#forecast_data ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/easy_weather/weather.rb', line 13 def forecast_data forecast["list"].each_with_index do |day, index| puts "Day #{index + 1}\n" puts "Temperature: #{day["main"]["temp"]} centigrades\n" puts "Weather: #{day["weather"][0]["description"]}\n" end "Take your precautions for the week!" end |
#temperature ⇒ Object
30 31 32 |
# File 'lib/easy_weather/weather.rb', line 30 def temperature "#{data["main"]["temp"]} centigrades" end |
#wind ⇒ Object
34 35 36 |
# File 'lib/easy_weather/weather.rb', line 34 def wind "#{data["wind"]["speed"]} meters/sec" end |