simple_weather 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/simple_weather.rb +16 -13
- metadata +1 -1
data/lib/simple_weather.rb
CHANGED
@@ -4,10 +4,12 @@ require 'net/http'
|
|
4
4
|
|
5
5
|
# api key from wunderground: 7b1e71b12f5535c0
|
6
6
|
module SimpleWeather
|
7
|
-
class Weather
|
8
|
-
|
7
|
+
class Weather
|
8
|
+
def initialize
|
9
|
+
@@conditions = {}
|
10
|
+
end
|
9
11
|
|
10
|
-
def
|
12
|
+
def processAllNodes(root, hash = {})
|
11
13
|
if root == nil
|
12
14
|
return
|
13
15
|
end
|
@@ -15,19 +17,19 @@ module SimpleWeather
|
|
15
17
|
processNodeAttr(root, hash)
|
16
18
|
if root.children.length > 0
|
17
19
|
root.children.each { |c|
|
18
|
-
|
20
|
+
processAllNodes(c, hash[root.name])
|
19
21
|
}
|
20
22
|
end
|
21
23
|
end
|
22
24
|
|
23
|
-
def
|
25
|
+
def processNodeAttr(node, hash = {})
|
24
26
|
hash[node.name]['attributes'] = {}
|
25
27
|
node.attributes.each { |k, v|
|
26
28
|
hash[node.name]['attributes']["#{k}"] = v.to_s
|
27
29
|
}
|
28
30
|
end
|
29
31
|
|
30
|
-
def
|
32
|
+
def updateWeather(city = 'College Park')
|
31
33
|
base_url = 'http://www.google.com/ig/api?weather='
|
32
34
|
url = URI.escape(base_url << city)
|
33
35
|
|
@@ -50,31 +52,31 @@ module SimpleWeather
|
|
50
52
|
return getData
|
51
53
|
end
|
52
54
|
|
53
|
-
def
|
55
|
+
def getImageUrl
|
54
56
|
@@conditions['weather']['current_conditions']['icon']['attributes']['data']
|
55
57
|
end
|
56
58
|
|
57
|
-
def
|
59
|
+
def getCondition
|
58
60
|
@@conditions['weather']['current_conditions']['condition']['attributes']['data']
|
59
61
|
end
|
60
62
|
|
61
|
-
def
|
63
|
+
def getTemp_f
|
62
64
|
@@conditions['weather']['current_conditions']['temp_f']['attributes']['data']
|
63
65
|
end
|
64
66
|
|
65
|
-
def
|
67
|
+
def getTemp_c
|
66
68
|
@@conditions['weather']['current_conditions']['temp_c']['attributes']['data']
|
67
69
|
end
|
68
70
|
|
69
|
-
def
|
71
|
+
def getHumidity
|
70
72
|
@@conditions['weather']['current_conditions']['humidity']['attributes']['data']
|
71
73
|
end
|
72
74
|
|
73
|
-
def
|
75
|
+
def getWindCondition
|
74
76
|
@@conditions['weather']['current_conditions']['wind_condition']['attributes']['data']
|
75
77
|
end
|
76
78
|
|
77
|
-
def
|
79
|
+
def getData
|
78
80
|
data = {}
|
79
81
|
data['icon_url'] = getImageUrl
|
80
82
|
data['conditon'] = getCondition
|
@@ -84,4 +86,5 @@ module SimpleWeather
|
|
84
86
|
end
|
85
87
|
end
|
86
88
|
end
|
89
|
+
|
87
90
|
# ActionView::Base.send(:include, SimpleWeather) if defined?(ActionView::Base)
|