class CptecInpe
Constants
- VERSION
Attributes
location_code[R]
Public Class Methods
new(str)
click to toggle source
# File lib/cptec_inpe.rb, line 12 def initialize(str) self.location = str unless str.nil? end
Public Instance Methods
find_location(location)
click to toggle source
# File lib/cptec_inpe.rb, line 26 def find_location(location) options = { query: { city: Utils.normalize(location) } } path = build_path "/listaCidades" cities = self.class.get(path, options)["cidades"] return if cities.nil? return cities["cidade"].first if cities["cidade"].is_a?(Array) cities["cidade"] end
forecast()
click to toggle source
# File lib/cptec_inpe.rb, line 52 def forecast response = get("/cidade/%s/previsao.xml") get_forecast(response) if response end
location=(location)
click to toggle source
# File lib/cptec_inpe.rb, line 16 def location=(location) @location_code = nil city = find_location(location) unless city.nil? @location_code = city["id"] end end
waves_next_days()
click to toggle source
# File lib/cptec_inpe.rb, line 47 def waves_next_days response = get("/cidade/%s/todos/tempos/ondas.xml") get_forecast(response) if response end
waves_today()
click to toggle source
# File lib/cptec_inpe.rb, line 42 def waves_today response = get("/cidade/%s/dia/0/ondas.xml") response["cidade"] if response end
Private Instance Methods
build_path(path)
click to toggle source
# File lib/cptec_inpe.rb, line 67 def build_path(path) "/XML#{path}" end
get(path_format)
click to toggle source
# File lib/cptec_inpe.rb, line 59 def get(path_format) unless @location_code.nil? path = build_path(path_format % @location_code) response = self.class.get(path) response if response.success? end end
get_forecast(response)
click to toggle source
# File lib/cptec_inpe.rb, line 71 def get_forecast(response) response["cidade"]["previsao"] end