yahoo_weatherman_extended 1.2.0

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/i18n/pt-br.yml ADDED
@@ -0,0 +1,62 @@
1
+ 0: Tornado
2
+ 1: Tempestade Tropical
3
+ 2: Furacão
4
+ 3: Tempestades Severas
5
+ 4: Tempestades
6
+ 5: Chuva com Neve
7
+ 6: Chuva com Granizo
8
+ 7: Chova com Neve e Granizo
9
+ 8: Geada
10
+ 9: Garoa
11
+ 10: Geada
12
+ 11: Chuva
13
+ 12: Chuva
14
+ 13: Flocos de Neve
15
+ 14: Neve Calma
16
+ 15: Nevasca
17
+ 16: Neve
18
+ 17: Granizo
19
+ 18: Granizo
20
+ 19: Poeira
21
+ 20: Neblina
22
+ 21: Nevoeiro
23
+ 22: Nevoeiro
24
+ 23: Tempestuoso
25
+ 24: Ventoso
26
+ 25: Frio
27
+ 26: Nublado
28
+ 27: Predominantemente Nublado (noite)
29
+ 28: Predominantemente Nublado
30
+ 29: Parcialmente Nublado (noite)
31
+ 30: Parcialmente Nublado
32
+ 31: Céu Limpo
33
+ 32: Ensolarado
34
+ 33: Limpo
35
+ 34: Limpo
36
+ 35: Misto de Chuva e Granizo
37
+ 36: Quente
38
+ 37: Tempestades Isoladas
39
+ 38: Tempestades Intermitentes
40
+ 39: Tempestades Intermitentes
41
+ 40: Chuvas Intermitentes
42
+ 41: Bastante Neve
43
+ 42: Neve
44
+ 43: Bastante Neve
45
+ 44: Parcialmente Nublado
46
+ 45: Tempestade
47
+ 46: Neve
48
+ 47: Chuvas Isoladas
49
+ 3200: Não Disponível
50
+
51
+ locations:
52
+ Brazil: Brasil
53
+
54
+ forecasts:
55
+ days:
56
+ Mon: Segunda-feira
57
+ Tue: Terça-feira
58
+ Wed: Quarta-feira
59
+ Thu: Quinta-feira
60
+ Fri: Sexta-feira
61
+ Sat: Sábado
62
+ Sun: Domingo
@@ -0,0 +1,69 @@
1
+ # coding: utf-8
2
+ path = File.expand_path(File.dirname(__FILE__))
3
+ $LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
4
+
5
+ require 'rubygems'
6
+
7
+ require 'yaml'
8
+ require 'open-uri'
9
+ require 'nokogiri'
10
+
11
+ require 'yahoo_weatherman/i18n'
12
+ require 'yahoo_weatherman/image'
13
+ require 'yahoo_weatherman/response'
14
+
15
+ module Weatherman
16
+
17
+ VERSION = '1.0.3'
18
+
19
+ URI = 'http://weather.yahooapis.com/forecastrss'
20
+
21
+ # = Client
22
+ #
23
+ # The weatherman client. Where it all begins.
24
+ #
25
+ class Client
26
+ attr_reader :options
27
+
28
+ #
29
+ # Accepts a optional hash containing the client options.
30
+ #
31
+ # Options:
32
+ #
33
+ # +unit+: the unit used for the temperature (defaults to Celsius).
34
+ # "f" => Fahrenheight
35
+ # "c" => Celsius
36
+ #
37
+ # +lang+: the language used in the response
38
+ #
39
+ def initialize(options = {})
40
+ @options = options
41
+ @uri = options[:url] || URI
42
+ end
43
+
44
+ #
45
+ # Just pass in a +woeid+ and it will return a Weatherman::Response object:w
46
+ #
47
+ def lookup_by_city_code(city_code)
48
+ raw = get request_url(city_code)
49
+ Response.new(raw, options[:lang])
50
+ end
51
+
52
+ private
53
+ def request_url(city_code)
54
+ @uri + query_string(city_code)
55
+ end
56
+
57
+ def query_string(city_code)
58
+ "?p=#{city_code}&u=#{degrees_units}"
59
+ end
60
+
61
+ def degrees_units
62
+ (options[:unit] || 'c').downcase
63
+ end
64
+
65
+ def get(url)
66
+ open(url) { |stream| stream.read }
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,58 @@
1
+ # coding: utf-8
2
+ module Weatherman
3
+ class I18N
4
+ I18N_YAML_DIR = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'i18n'))
5
+
6
+ LANGUAGES = {}
7
+
8
+ attr_accessor :language
9
+
10
+ def initialize(language)
11
+ @language = language
12
+ end
13
+
14
+ def translate!(attributes)
15
+ if i18n?
16
+ translate_text! attributes
17
+ translate_days! attributes
18
+ translate_locations! attributes
19
+ end
20
+ attributes
21
+ end
22
+
23
+ private
24
+ def translate_text!(attributes)
25
+ translate_attribute('text', attributes, language_translations, 'code')
26
+ end
27
+
28
+ def translate_days!(attributes)
29
+ translate_attribute('day', attributes, language_translations['forecasts']['days'])
30
+ end
31
+
32
+ def translate_locations!(attributes)
33
+ (%w(city country region) & attributes.keys).each do |key|
34
+ translate_attribute(key, attributes, language_translations['locations'])
35
+ end
36
+ end
37
+
38
+ def translate_attribute(name, attributes, translations, change_by = nil)
39
+ translation_key = attributes[(change_by || name)]
40
+
41
+ if attributes[name] and translations[translation_key]
42
+ attributes[name] = translations[translation_key]
43
+ end
44
+ end
45
+
46
+ def language_translations
47
+ LANGUAGES[language] ||= load_language_yaml!
48
+ end
49
+
50
+ def load_language_yaml!
51
+ YAML::load File.read(File.join(I18N_YAML_DIR, language + '.yml'))
52
+ end
53
+
54
+ def i18n?
55
+ !!@language
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,16 @@
1
+ # coding: utf-8
2
+ module Weatherman
3
+ # == Image
4
+ #
5
+ # A hash-like object with the weather image attributes (width, height, url, etc..)
6
+ #
7
+ class Image
8
+ def initialize(doc)
9
+ @image_root = doc
10
+ end
11
+
12
+ def [](attr)
13
+ @image_root.xpath(attr).first.content
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,201 @@
1
+ # coding: utf-8
2
+ module Weatherman
3
+
4
+ # = Response
5
+ #
6
+ # This is where we get access to the contents parsed by Nokogiri in a object-oriented way.
7
+ # We also use this class to do the i18n stuff.
8
+ #
9
+ class Response
10
+
11
+ attr_accessor :document_root
12
+
13
+ def initialize(raw, language = nil)
14
+ @document_root = Nokogiri::XML(raw).xpath('rss/channel')
15
+ @i18n = Weatherman::I18N.new(language)
16
+ end
17
+
18
+ #
19
+ # Returns a hash containing the actual weather condition details:
20
+ #
21
+ # condition = response.condition
22
+ # condition['text'] => "Tornado"
23
+ # condition['code'] => 0
24
+ # condition['temp'] => 21
25
+ # condition['date'] => #<Date: -1/2,0,2299161>
26
+ #
27
+ def condition
28
+ condition = item_attribute('yweather:condition')
29
+ translate! do_convertions(condition, [:code, :to_i], [:temp, :to_i], [:date, :to_date], :text)
30
+ end
31
+
32
+ #
33
+ # Wind's details:
34
+ #
35
+ # wind = response.wind
36
+ # wind['chill'] => 21
37
+ # wind['direction'] => 340
38
+ # wind['chill'] => 9.66
39
+ #
40
+ def wind
41
+ do_convertions(attribute('yweather:wind'), [:chill, :to_i], [:direction, :to_i], [:speed, :to_f])
42
+ end
43
+
44
+ #
45
+ # Forecasts for the next 2 days.
46
+ #
47
+ # forecast = response.forecasts.first
48
+ # forecast['low'] => 20
49
+ # forecast['high'] => 31
50
+ # forecast['text'] => "Tornado"
51
+ # forecast['code'] => 0
52
+ # forecast['day'] => "Sat"
53
+ #
54
+ def forecasts
55
+ convertions = [[:date, :to_date], [:low, :to_i], [:high, :to_i], [:code, :to_i], :day, :text]
56
+ item_attribute('yweather:forecast').collect do |forecast|
57
+ translate! do_convertions(forecast, *convertions)
58
+ end
59
+ end
60
+
61
+ #
62
+ # Location:
63
+ #
64
+ # location = response.location
65
+ # location['country'] => "Brazil"
66
+ # location['region'] => "MG"
67
+ # location['city'] => Belo Horizonte
68
+ #
69
+ def location
70
+ translate! attribute('yweather:location')
71
+ end
72
+
73
+ # Units:
74
+ #
75
+ # units = response.units
76
+ # units['temperature'] => "C"
77
+ # units['distance'] => "km"
78
+ # units['pressure'] => "mb"
79
+ # units['speed'] => "km/h"
80
+ #
81
+ def units
82
+ attribute('yweather:units')
83
+ end
84
+
85
+ #
86
+ # Astronomy:
87
+ #
88
+ # astronomy = response.astronomy
89
+ # astronomy['sunrise'] => "6:01 am"
90
+ # astronomy['sunset'] => "7:20 pm"
91
+ #
92
+ def astronomy
93
+ attribute('yweather:astronomy')
94
+ end
95
+
96
+ #
97
+ # Atmosphere :
98
+ #
99
+ # atmosphere = response.atmosphere
100
+ # atmosphere['humidity'] => "62"
101
+ # atmosphere['visibility'] => "9.99"
102
+ # atmosphere['pressure'] => "982.05"
103
+ # atmosphere['rising'] => "0"
104
+ #
105
+ def atmosphere
106
+ atm = attribute('yweather:atmosphere')
107
+ do_convertions(atm, [:humidity, :to_f], [:visibility, :to_f], [:pressure, :to_f], [:rising, :to_f])
108
+ end
109
+
110
+ #
111
+ # Latitude:
112
+ #
113
+ # response.latitude => -49.90
114
+ def latitude
115
+ geo_attribute('lat')
116
+ end
117
+
118
+ #
119
+ # Longitude;
120
+ #
121
+ # response.longitude => -45.32
122
+ #
123
+ def longitude
124
+ geo_attribute('long')
125
+ end
126
+
127
+ #
128
+ # A hash like object providing image info:
129
+ #
130
+ # image = reponse.image
131
+ # image['width'] => 142
132
+ # image['height'] => 18
133
+ # image['title'] => "Yahoo! Weather"
134
+ # image['link'] => "http://weather.yahoo.com"
135
+ #
136
+ def image
137
+ image = Weatherman::Image.new(attribute('image'))
138
+ do_convertions(image, [:width, :to_i], [:height, :to_i], :title, :link, :url)
139
+ end
140
+
141
+ #
142
+ # Description image. You might gonna need this if you have to customize the
143
+ # forecast summary.
144
+ #
145
+ def description_image
146
+ parsed_description.css('img').first # there's only one
147
+ end
148
+
149
+ #
150
+ # A short HTML snippet (raw text) with a simple weather description.
151
+ #
152
+ def description
153
+ text_attribute('description')
154
+ end
155
+ alias :summary :description
156
+
157
+ #
158
+ # Description parsed by Nokogiri. This is better then #description
159
+ # if you have to walk through its nodes.
160
+ #
161
+ def parsed_description
162
+ @parsed_description ||= Nokogiri::HTML(description)
163
+ end
164
+
165
+ private
166
+ def attribute(attr, root = @document_root)
167
+ elements = root.xpath(attr)
168
+ elements.size == 1 ? elements.first : elements
169
+ end
170
+
171
+ def item_attribute(attr)
172
+ attribute(attr, document_root.xpath('item').first)
173
+ end
174
+
175
+ def geo_attribute(attr)
176
+ item_attribute('geo:' + attr).children.first.text.to_f
177
+ end
178
+
179
+ def text_attribute(attr)
180
+ item_attribute(attr).content
181
+ end
182
+
183
+ def do_convertions(attributes, *pairs)
184
+ pairs.inject({}) do |hash, (attr, method)|
185
+ key = attr.to_s
186
+ hash[key] = convert(attributes[key], method)
187
+ hash
188
+ end
189
+ end
190
+
191
+ def convert(value, method)
192
+ return value unless method
193
+ method == :to_date ? Date.parse(value) : value.send(method)
194
+ end
195
+
196
+ def translate!(attributes)
197
+ @i18n.translate! attributes
198
+ end
199
+ end
200
+ end
201
+
@@ -0,0 +1,49 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2
+ <rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
3
+ <channel>
4
+
5
+ <title>Yahoo! Weather - Belo Horizonte, BR</title>
6
+ <link>http://us.rd.yahoo.com/dailynews/rss/weather/Belo_Horizonte__BR/*http://weather.yahoo.com/forecast/BRXX0033_c.html</link>
7
+ <description>Yahoo! Weather for Belo Horizonte, BR</description>
8
+ <language>en-us</language>
9
+ <lastBuildDate>Sat, 13 Mar 2010 6:00 pm LST</lastBuildDate>
10
+ <ttl>60</ttl>
11
+ <yweather:location city="Belo Horizonte" region="MG" country="Brazil"/>
12
+
13
+ <yweather:units temperature="C" distance="km" pressure="mb" speed="km/h"/>
14
+ <yweather:wind chill="28" direction="340" speed="9.66" />
15
+ <yweather:atmosphere humidity="62" visibility="9.99" pressure="982.05" rising="0" />
16
+ <yweather:astronomy sunrise="5:57 am" sunset="6:13 pm"/>
17
+ <image>
18
+ <title>Yahoo! Weather</title>
19
+ <width>142</width>
20
+ <height>18</height>
21
+ <link>http://weather.yahoo.com</link>
22
+ <url>http://l.yimg.com/a/i/us/nws/th/main_142b.gif</url>
23
+ </image>
24
+ <item>
25
+
26
+ <title>Conditions for Belo Horizonte, BR at 6:00 pm LST</title>
27
+ <geo:lat>-19.95</geo:lat>
28
+ <geo:long>-43.93</geo:long>
29
+ <link>http://us.rd.yahoo.com/dailynews/rss/weather/Belo_Horizonte__BR/*http://weather.yahoo.com/forecast/BRXX0033_c.html</link>
30
+ <pubDate>Sat, 13 Mar 2010 6:00 pm LST</pubDate>
31
+ <yweather:condition text="Mostly Cloudy" code="28" temp="28" date="Sat, 13 Mar 2010 6:00 pm LST" />
32
+ <description><![CDATA[
33
+ <img src="http://l.yimg.com/a/i/us/we/52/28.gif"/><br />
34
+ <b>Current Conditions:</b><br />
35
+ Mostly Cloudy, 28 C<BR />
36
+ <BR /><b>Forecast:</b><BR />
37
+ Sat - Showers. High: 27 Low: 18<br />
38
+ Sun - Scattered Thunderstorms. High: 27 Low: 18<br />
39
+ <br />
40
+ <a href="http://us.rd.yahoo.com/dailynews/rss/weather/Belo_Horizonte__BR/*http://weather.yahoo.com/forecast/BRXX0033_c.html">Full Forecast at Yahoo! Weather</a><BR/><BR/>
41
+ (provided by <a href="http://www.weather.com" >The Weather Channel</a>)<br/>
42
+ ]]></description>
43
+ <yweather:forecast day="Sat" date="13 Mar 2010" low="18" high="27" text="Showers" code="11" />
44
+ <yweather:forecast day="Sun" date="14 Mar 2010" low="18" high="27" text="Scattered Thunderstorms" code="38" />
45
+ <guid isPermaLink="false">BRXX0033_2010_03_13_18_00_LST</guid>
46
+ </item>
47
+
48
+ </channel>
49
+ </rss><!-- api5.weather.ac4.yahoo.com compressed/chunked Sat Mar 13 14:29:51 PST 2010 -->
@@ -0,0 +1,49 @@
1
+ <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2
+ <rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
3
+ <channel>
4
+
5
+ <title>Yahoo! Weather - Belo Horizonte, BR</title>
6
+ <link>http://us.rd.yahoo.com/dailynews/rss/weather/Belo_Horizonte__BR/*http://weather.yahoo.com/forecast/BRXX0033_f.html</link>
7
+ <description>Yahoo! Weather for Belo Horizonte, BR</description>
8
+ <language>en-us</language>
9
+ <lastBuildDate>Thu, 18 Mar 2010 12:00 am LST</lastBuildDate>
10
+ <ttl>60</ttl>
11
+ <yweather:location city="Belo Horizonte" region="MG" country="Brazil"/>
12
+
13
+ <yweather:units temperature="F" distance="mi" pressure="in" speed="mph"/>
14
+ <yweather:wind chill="66" direction="100" speed="2" />
15
+ <yweather:atmosphere humidity="88" visibility="6.21" pressure="30.15" rising="0" />
16
+ <yweather:astronomy sunrise="5:59 am" sunset="6:08 pm"/>
17
+ <image>
18
+ <title>Yahoo! Weather</title>
19
+ <width>142</width>
20
+ <height>18</height>
21
+ <link>http://weather.yahoo.com</link>
22
+ <url>http://l.yimg.com/a/i/us/nws/th/main_142b.gif</url>
23
+ </image>
24
+ <item>
25
+
26
+ <title>Conditions for Belo Horizonte, BR at 12:00 am LST</title>
27
+ <geo:lat>-19.95</geo:lat>
28
+ <geo:long>-43.93</geo:long>
29
+ <link>http://us.rd.yahoo.com/dailynews/rss/weather/Belo_Horizonte__BR/*http://weather.yahoo.com/forecast/BRXX0033_f.html</link>
30
+ <pubDate>Thu, 18 Mar 2010 12:00 am LST</pubDate>
31
+ <yweather:condition text="Fair" code="33" temp="66" date="Thu, 18 Mar 2010 12:00 am LST" />
32
+ <description><![CDATA[
33
+ <img src="http://l.yimg.com/a/i/us/we/52/33.gif"/><br />
34
+ <b>Current Conditions:</b><br />
35
+ Fair, 66 F<BR />
36
+ <BR /><b>Forecast:</b><BR />
37
+ Thu - Showers. High: 75 Low: 63<br />
38
+ Fri - Scattered Thunderstorms. High: 79 Low: 63<br />
39
+ <br />
40
+ <a href="http://us.rd.yahoo.com/dailynews/rss/weather/Belo_Horizonte__BR/*http://weather.yahoo.com/forecast/BRXX0033_f.html">Full Forecast at Yahoo! Weather</a><BR/><BR/>
41
+ (provided by <a href="http://www.weather.com" >The Weather Channel</a>)<br/>
42
+ ]]></description>
43
+ <yweather:forecast day="Thu" date="18 Mar 2010" low="63" high="75" text="Showers" code="11" />
44
+ <yweather:forecast day="Fri" date="19 Mar 2010" low="63" high="79" text="Scattered Thunderstorms" code="38" />
45
+ <guid isPermaLink="false">BRXX0033_2010_03_18_0_00_LST</guid>
46
+ </item>
47
+
48
+ </channel>
49
+ </rss>
@@ -0,0 +1,36 @@
1
+ path = File.expand_path(File.join([File.dirname(__FILE__), "..", "lib"]))
2
+ $LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
3
+
4
+ require 'rubygems'
5
+ require 'fakeweb'
6
+ require 'yahoo_weatherman'
7
+ require 'spec'
8
+
9
+ def celsius_fixture
10
+ filepath = File.expand_path(File.join([File.dirname(__FILE__), "files", "belo_horizonte_c.rss"]))
11
+ File.read filepath
12
+ end
13
+
14
+ def fahrenheight_fixture
15
+ filepath = File.expand_path(File.join([File.dirname(__FILE__), "files", "belo_horizonte_f.rss"]))
16
+ File.read filepath
17
+ end
18
+
19
+ FakeWeb.allow_net_connect = false
20
+ FakeWeb.register_uri(:get, "http://weather.yahooapis.com/forecastrss?w=455821&u=c", :body => celsius_fixture)
21
+ FakeWeb.register_uri(:get, "http://weather.yahooapis.com/forecastrss?w=455821&u=f", :body => fahrenheight_fixture)
22
+
23
+ module YAML
24
+ class << self
25
+
26
+ alias original_load load
27
+ def load(ignored_arg)
28
+ original_load(test_translation_file_stream)
29
+ end
30
+
31
+ def test_translation_file_stream
32
+ File.read(File.join([File.dirname(__FILE__), 'files', 'test_i18n.yml']))
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Weatherman::I18N do
5
+ before do
6
+ @response = Weatherman::Client.new(:lang => 'pt-br').lookup_by_woeid 455821
7
+ end
8
+
9
+ it 'should translate the conditions details' do
10
+ @response.condition['text'].should == 'Predominantemente Nublado'
11
+ end
12
+
13
+ it 'should translate the location details' do
14
+ @response.location['country'].should == 'Brasil'
15
+ @response.location['city'].should == 'Santa Luzia'
16
+ @response.location['region'].should == 'Minas Gerais'
17
+ end
18
+
19
+ it 'should translate the forecasts details' do
20
+ @response.forecasts.first['text'].should == 'Chuva'
21
+ @response.forecasts.last['text'].should == 'Tempestades Intermitentes'
22
+ @response.forecasts.first['day'].should == 'Sábado'
23
+ @response.forecasts.last['day'].should == 'Domingo'
24
+ end
25
+ end
26
+
27
+
@@ -0,0 +1,117 @@
1
+ # coding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Weatherman::Response do
5
+ before do
6
+ @response = Weatherman::Client.new.lookup_by_woeid 455821
7
+ end
8
+
9
+ it 'should provide a location' do
10
+ @response.location['city'].should == 'Belo Horizonte'
11
+ @response.location['region'].should == 'MG'
12
+ @response.location['country'].should == 'Brazil'
13
+ end
14
+
15
+ it 'should provide a weather condition' do
16
+ @response.condition['code'].should == 28
17
+ @response.condition['temp'].should == 28
18
+ @response.condition['text'].should == 'Mostly Cloudy'
19
+ @response.condition['date'].should == Date.parse('Sat, 13 Mar 2010 11:00 pm LST')
20
+ end
21
+
22
+ it 'should provide the units used' do
23
+ @response.units['temperature'].should == 'C'
24
+ @response.units['distance'].should == 'km'
25
+ @response.units['pressure'].should == 'mb'
26
+ @response.units['speed'].should == 'km/h'
27
+ end
28
+
29
+ it 'should provide information about the wind' do
30
+ @response.wind['chill'].should == 28
31
+ @response.wind['direction'].should == 340
32
+ @response.wind['speed'].should == 9.66
33
+ end
34
+
35
+ it 'should provide astronomy information' do
36
+ @response.astronomy['sunrise'].should == '5:57 am'
37
+ @response.astronomy['sunset'].should == '6:13 pm'
38
+ end
39
+
40
+ it 'should provide atmosphere information' do
41
+ @response.atmosphere['humidity'].should == 62
42
+ @response.atmosphere['visibility'].should == 9.99
43
+ @response.atmosphere['pressure'].should == 982.05
44
+ @response.atmosphere['rising'].should be_zero
45
+ end
46
+
47
+ it 'should get the next 2 forecasts' do
48
+ first = @response.forecasts.first
49
+ first['day'].should == 'Sat'
50
+ first['date'].should == Date.parse('13 Mar 2010')
51
+ first['low'].should == 18
52
+ first['high'].should == 27
53
+ first['text'].should == 'Showers'
54
+ first['code'].should == 11
55
+
56
+ last = @response.forecasts.last
57
+ last['day'].should == 'Sun'
58
+ last['date'].should == Date.parse('14 Mar 2010')
59
+ last['low'].should == 18
60
+ last['high'].should == 27
61
+ last['text'].should == 'Scattered Thunderstorms'
62
+ last['code'].should == 38
63
+ end
64
+
65
+ it 'should provide latitude and longitude' do
66
+ @response.latitude.should == -19.95
67
+ @response.longitude.should == -43.93
68
+ end
69
+
70
+ it 'should provide a description' do
71
+ description = <<-DESCRIPTION
72
+
73
+ <img src="http://l.yimg.com/a/i/us/we/52/28.gif"/><br />
74
+ <b>Current Conditions:</b><br />
75
+ Mostly Cloudy, 28 C<BR />
76
+ <BR /><b>Forecast:</b><BR />
77
+ Sat - Showers. High: 27 Low: 18<br />
78
+ Sun - Scattered Thunderstorms. High: 27 Low: 18<br />
79
+ <br />
80
+ <a href="http://us.rd.yahoo.com/dailynews/rss/weather/Belo_Horizonte__BR/*http://weather.yahoo.com/forecast/BRXX0033_c.html">Full Forecast at Yahoo! Weather</a><BR/><BR/>
81
+ (provided by <a href="http://www.weather.com" >The Weather Channel</a>)<br/>
82
+ DESCRIPTION
83
+
84
+ @response.description.should == description
85
+ @response.description.should == @response.summary
86
+ end
87
+
88
+ it 'should provide the weather image attributes' do
89
+ image = @response.image
90
+ image['width'].should == 142
91
+ image['height'].should == 18
92
+ image['title'].should == 'Yahoo! Weather'
93
+ image['link'].should == 'http://weather.yahoo.com'
94
+ image['url'].should == 'http://l.yimg.com/a/i/us/nws/th/main_142b.gif'
95
+ end
96
+
97
+ it 'should provide the forecast description icon' do
98
+ image = @response.description_image
99
+ image['src'].should == 'http://l.yimg.com/a/i/us/we/52/28.gif'
100
+ end
101
+
102
+ context 'using fahrenheiht as temperature unit' do
103
+
104
+ it 'should return the temperature as fahrenheight' do
105
+ client = Weatherman::Client.new :unit => 'F'
106
+ response = client.lookup_by_woeid 455821
107
+
108
+ response.units['temperature'].should == 'F'
109
+ response.forecasts.first['low'].should == 63
110
+ response.forecasts.last['low'].should == 63
111
+ response.forecasts.first['high'].should == 75
112
+ response.forecasts.last['high'].should == 79
113
+ response.condition['temp'].should == 66
114
+ end
115
+ end
116
+
117
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Weatherman::Client do
4
+ before do
5
+ @client = Weatherman::Client.new
6
+ end
7
+
8
+ it 'should lookup by woeid' do
9
+ response = @client.lookup_by_woeid 455821
10
+ response.should be_instance_of(Weatherman::Response)
11
+ end
12
+
13
+ end
@@ -0,0 +1,22 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = "yahoo_weatherman_extended"
3
+ gem.version = "1.2.0"
4
+ gem.authors = ["Dalto Curvelano Junior", "Mahmoud Said"]
5
+ gem.description = "a fork of leandroo/yahoo_weatherman, A ruby wrapper to the Yahoo! Weather feed with i18n support, to handle the updated parameters for yahoo weather service parameters."
6
+ gem.summary = "A ruby wrapper to the Yahoo! Weather feed with i18n support."
7
+ gem.files = [
8
+ "yahoo_weatherman.gemspec",
9
+ "lib/yahoo_weatherman/image.rb",
10
+ "lib/yahoo_weatherman/response.rb",
11
+ "lib/yahoo_weatherman/i18n.rb",
12
+ "lib/yahoo_weatherman.rb",
13
+ "i18n/pt-br.yml",
14
+ "spec/files/belo_horizonte_c.rss",
15
+ "spec/files/belo_horizonte_f.rss",
16
+ "spec/spec_helper.rb",
17
+ "spec/yahoo_weatherman/response_spec.rb",
18
+ "spec/yahoo_weatherman/yahoo_weatherman_spec.rb",
19
+ "spec/yahoo_weatherman/i18n_spec.rb"
20
+ ]
21
+ gem.homepage = "http://github.com/modsaid/yahoo_weatherman"
22
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yahoo_weatherman_extended
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.2.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dalto Curvelano Junior
9
+ - Mahmoud Said
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2011-05-09 00:00:00.000000000 +02:00
14
+ default_executable:
15
+ dependencies: []
16
+ description: a fork of leandroo/yahoo_weatherman, A ruby wrapper to the Yahoo! Weather
17
+ feed with i18n support, to handle the updated parameters for yahoo weather service
18
+ parameters.
19
+ email:
20
+ executables: []
21
+ extensions: []
22
+ extra_rdoc_files: []
23
+ files:
24
+ - yahoo_weatherman.gemspec
25
+ - lib/yahoo_weatherman/image.rb
26
+ - lib/yahoo_weatherman/response.rb
27
+ - lib/yahoo_weatherman/i18n.rb
28
+ - lib/yahoo_weatherman.rb
29
+ - i18n/pt-br.yml
30
+ - spec/files/belo_horizonte_c.rss
31
+ - spec/files/belo_horizonte_f.rss
32
+ - spec/spec_helper.rb
33
+ - spec/yahoo_weatherman/response_spec.rb
34
+ - spec/yahoo_weatherman/yahoo_weatherman_spec.rb
35
+ - spec/yahoo_weatherman/i18n_spec.rb
36
+ has_rdoc: true
37
+ homepage: http://github.com/modsaid/yahoo_weatherman
38
+ licenses: []
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ none: false
45
+ requirements:
46
+ - - ! '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ requirements: []
56
+ rubyforge_project:
57
+ rubygems_version: 1.6.2
58
+ signing_key:
59
+ specification_version: 3
60
+ summary: A ruby wrapper to the Yahoo! Weather feed with i18n support.
61
+ test_files: []