Class: Weather
- Inherits:
-
Object
- Object
- Weather
- Defined in:
- lib/easy_weather/weather.rb
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.
7 8 9 10 |
# File 'lib/easy_weather/weather.rb', line 7 def initialize(city) @data = self.get_general_data(city) @forecast = self.get_forecast_data(5, city) end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
5 6 7 |
# File 'lib/easy_weather/weather.rb', line 5 def data @data end |
#forecast ⇒ Object
Returns the value of attribute forecast.
5 6 7 |
# File 'lib/easy_weather/weather.rb', line 5 def forecast @forecast end |
Instance Method Details
#astronomy_data ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/easy_weather/weather.rb', line 21 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
37 38 39 40 41 42 43 44 |
# File 'lib/easy_weather/weather.rb', line 37 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
12 13 14 15 16 17 18 19 |
# File 'lib/easy_weather/weather.rb', line 12 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 "Have a nice week!" end |
#temperature ⇒ Object
29 30 31 |
# File 'lib/easy_weather/weather.rb', line 29 def temperature "#{@data["main"]["temp"]} centigrades" end |
#wind ⇒ Object
33 34 35 |
# File 'lib/easy_weather/weather.rb', line 33 def wind "#{@data["wind"]["speed"]} meters/sec" end |