Class: Tropical::OpenWeatherMap
- Inherits:
-
Object
- Object
- Tropical::OpenWeatherMap
- Defined in:
- lib/tropical.rb
Constant Summary collapse
- BASE_URL =
"https://api.openweathermap.org/data/2.5/forecast?".freeze
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #city_name ⇒ Object
- #coord ⇒ Object
- #country ⇒ Object
- #current_date ⇒ Object
- #current_temp ⇒ Object
- #current_weather ⇒ Object
- #full_sumary ⇒ Object
-
#initialize(params) ⇒ OpenWeatherMap
constructor
A new instance of OpenWeatherMap.
- #population ⇒ Object
- #scale ⇒ Object
- #sumary_current_day ⇒ Object
- #sumary_days_forecast ⇒ Object
Constructor Details
#initialize(params) ⇒ OpenWeatherMap
Returns a new instance of OpenWeatherMap.
14 15 16 17 18 19 |
# File 'lib/tropical.rb', line 14 def initialize(params) @params = params response = post(request_params) load_data(response) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
12 13 14 |
# File 'lib/tropical.rb', line 12 def data @data end |
#params ⇒ Object (readonly)
Returns the value of attribute params.
12 13 14 |
# File 'lib/tropical.rb', line 12 def params @params end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
12 13 14 |
# File 'lib/tropical.rb', line 12 def status @status end |
Instance Method Details
#city_name ⇒ Object
21 22 23 |
# File 'lib/tropical.rb', line 21 def city_name data["city"]["name"] end |
#coord ⇒ Object
33 34 35 |
# File 'lib/tropical.rb', line 33 def coord data["city"]["coord"].transform_keys(&:to_sym) end |
#country ⇒ Object
25 26 27 |
# File 'lib/tropical.rb', line 25 def country data["city"]["country"] end |
#current_date ⇒ Object
37 38 39 |
# File 'lib/tropical.rb', line 37 def current_date list.first[:dt] end |
#current_temp ⇒ Object
41 42 43 |
# File 'lib/tropical.rb', line 41 def current_temp list.first[:temp] end |
#current_weather ⇒ Object
45 46 47 |
# File 'lib/tropical.rb', line 45 def current_weather list.first[:description] end |
#full_sumary ⇒ Object
58 59 60 61 62 |
# File 'lib/tropical.rb', line 58 def full_sumary "#{sumary_current_day} "\ "Média para os próximos dias: "\ "#{sumary_days_forecast}" end |
#population ⇒ Object
29 30 31 |
# File 'lib/tropical.rb', line 29 def population data["city"]["population"] end |
#scale ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/tropical.rb', line 49 def scale units = params[:units] return "°C" if units == "metric" return "°F" if units == "imperial" "°K" end |
#sumary_current_day ⇒ Object
64 65 66 67 |
# File 'lib/tropical.rb', line 64 def sumary_current_day "#{current_temp.round}#{scale} e #{current_weather} em "\ "#{city_name} em #{current_date.strftime("%d/%m")}." end |
#sumary_days_forecast ⇒ Object
69 70 71 72 73 74 75 |
# File 'lib/tropical.rb', line 69 def sumary_days_forecast list = average_temp_by_days.map do |x| "#{x[:average]}#{scale} em #{x[:day].strftime("%d/%m")}" end "#{list.to_sentence(words_connector: ", ", last_word_connector: " e ")}." end |