Class: CptecInpe

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/cptec_inpe.rb,
lib/cptec_inpe/version.rb

Constant Summary collapse

VERSION =
"0.1.2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ CptecInpe

Returns a new instance of CptecInpe.



12
13
14
# File 'lib/cptec_inpe.rb', line 12

def initialize(str)
  self.location = str unless str.nil?
end

Instance Attribute Details

#location_codeObject (readonly)

Returns the value of attribute location_code.



10
11
12
# File 'lib/cptec_inpe.rb', line 10

def location_code
  @location_code
end

Instance Method Details

#find_location(location) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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

#forecastObject



52
53
54
55
# File 'lib/cptec_inpe.rb', line 52

def forecast
  response = get("/cidade/%s/previsao.xml")
  get_forecast(response) if response
end

#location=(location) ⇒ Object



16
17
18
19
20
21
22
23
24
# 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_daysObject



47
48
49
50
# 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_todayObject



42
43
44
45
# File 'lib/cptec_inpe.rb', line 42

def waves_today
  response = get("/cidade/%s/dia/0/ondas.xml")
  response["cidade"] if response
end