Class: Weather

Inherits:
Object
  • Object
show all
Defined in:
lib/easy_weather/weather.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#dataObject

Returns the value of attribute data.



5
6
7
# File 'lib/easy_weather/weather.rb', line 5

def data
  @data
end

#forecastObject

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_dataObject



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_dataObject



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_dataObject



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

#temperatureObject



29
30
31
# File 'lib/easy_weather/weather.rb', line 29

def temperature
  "#{@data["main"]["temp"]} centigrades" 
end

#windObject



33
34
35
# File 'lib/easy_weather/weather.rb', line 33

def wind
  "#{@data["wind"]["speed"]} meters/sec"
end