Class: DamnWeather::Forecast
- Inherits:
-
Object
- Object
- DamnWeather::Forecast
show all
- Includes:
- Weather
- Defined in:
- lib/damn_weather/forecast.rb
Constant Summary
Constants included
from Weather
Weather::APP_ID
Instance Method Summary
collapse
Methods included from Weather
#geo, #weather_icons
Methods included from Emoji
#cloudy, #extreme, #fog_wind, #heavy_rain, #light_rain, #partly_cloudy, #snow, #sunny, #thunder
Constructor Details
#initialize(days) ⇒ Forecast
Returns a new instance of Forecast.
5
6
7
|
# File 'lib/damn_weather/forecast.rb', line 5
def initialize(days)
@count = days * 8
end
|
Instance Method Details
#build_table(data) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'lib/damn_weather/forecast.rb', line 22
def build_table(data)
rows = []
data.each do |k|
date = Date.parse(k['dt_txt']).strftime(format='%d-%m-%y')
time = k['dt_txt'][11...-3]
temp = k['main']['temp'].to_i
icons = weather_icons(k['weather'].first['id']).join(' ')
description = k['weather'].first['description']
rows << [icons, "#{temp}\u00B0C", description, time, date]
end
puts Terminal::Table.new(:title => "Forecast for #{city} (#{country})", :rows => rows, :style => { :width => 80 })
end
|
#city ⇒ Object
14
15
16
|
# File 'lib/damn_weather/forecast.rb', line 14
def city
weather['city']['name']
end
|
#country ⇒ Object
18
19
20
|
# File 'lib/damn_weather/forecast.rb', line 18
def country
weather['city']['country']
end
|
#info ⇒ Object
35
36
37
38
39
|
# File 'lib/damn_weather/forecast.rb', line 35
def info
weather.each do |key, response|
build_table(response) if key == 'list'
end
end
|
#weather ⇒ Object
9
10
11
12
|
# File 'lib/damn_weather/forecast.rb', line 9
def weather
data = open("http://api.openweathermap.org/data/2.5/forecast?lat=#{geo.lat}&lon=#{geo.lng}&cnt=#{@count}&units=metric&APPID=#{APP_ID}").read
JSON.parse(data)
end
|