yahoo_weatherman 0.9 → 1.0.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.
@@ -9,13 +9,9 @@ module Weatherman
9
9
 
10
10
  attr_accessor :document_root
11
11
 
12
- attr_accessor :language
13
-
14
- LANGUAGES = {}
15
-
16
12
  def initialize(raw, language = nil)
17
13
  @document_root = Nokogiri::XML.parse(raw).xpath('rss/channel')
18
- @language = language
14
+ @i18n = I18N.new(language)
19
15
  end
20
16
 
21
17
  #
@@ -185,47 +181,8 @@ module Weatherman
185
181
  end
186
182
 
187
183
  def translate!(attributes)
188
- if i18n?
189
- translate_text! attributes
190
- translate_days! attributes
191
- translate_locations! attributes
192
- end
193
- attributes
194
- end
195
-
196
- def translate_text!(attributes)
197
- translate_attribute('text', attributes, language_translations, 'code')
198
- end
199
-
200
- def translate_days!(attributes)
201
- translate_attribute('day', attributes, language_translations['forecasts']['days'])
202
- end
203
-
204
- def translate_locations!(attributes)
205
- (%w[city country region] & attributes.keys).each do |key|
206
- translate_attribute(key, attributes, language_translations['locations'])
207
- end
208
- end
209
-
210
- def translate_attribute(name, attributes, translations, change_by = nil)
211
- translation_key = attributes[(change_by || name)]
212
-
213
- if attributes[name] and translations[translation_key]
214
- attributes[name] = translations[translation_key]
215
- end
216
- end
217
-
218
- def language_translations
219
- LANGUAGES[language] ||= load_language_yaml!
220
- end
221
-
222
- def load_language_yaml!
223
- stream = File.read(File.join([I18N_YAML_DIR, language + '.yml']))
224
- YAML::load(stream)
225
- end
226
-
227
- def i18n?
228
- !!@language
184
+ @i18n.translate! attributes
229
185
  end
230
186
  end
231
187
  end
188
+
@@ -5,17 +5,16 @@ require 'open-uri'
5
5
  require 'nokogiri'
6
6
  require 'yaml'
7
7
 
8
+ require 'yahoo_weatherman/i18n'
8
9
  require 'yahoo_weatherman/image'
9
10
  require 'yahoo_weatherman/response'
10
11
 
11
12
  module Weatherman
12
13
 
13
- VERSION = '0.9'
14
+ VERSION = '1.0.0'
14
15
 
15
16
  URI = 'http://weather.yahooapis.com/forecastrss'
16
17
 
17
- I18N_YAML_DIR = File.expand_path(File.join([File.dirname(__FILE__), '..', 'i18n']))
18
-
19
18
  # = Client
20
19
  #
21
20
  # The weatherman client. Where it all begins.
@@ -91,27 +91,6 @@ DESCRIPTION
91
91
  image['src'].should == 'http://l.yimg.com/a/i/us/we/52/28.gif'
92
92
  end
93
93
 
94
- context 'using internationalization' do
95
- before do
96
- @response = Weatherman::Client.new(:lang => 'pt-br').lookup_by_woeid 455821
97
- end
98
-
99
- it 'should translate the conditions details' do
100
- @response.condition['text'].should == 'Predominantemente Nublado'
101
- end
102
-
103
- it 'should translate the location details' do
104
- @response.location['country'].should == 'Brasil'
105
- end
106
-
107
- it 'should translate the forecasts details' do
108
- @response.forecasts.first['text'].should == 'Chuva'
109
- @response.forecasts.last['text'].should == 'Tempestades Intermitentes'
110
- @response.forecasts.first['day'].should == 'Sábado'
111
- @response.forecasts.last['day'].should == 'Domingo'
112
- end
113
- end
114
-
115
94
  context 'using fahrenheiht as temperature unit' do
116
95
 
117
96
  it 'should return the temperature as fahrenheight' do
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "yahoo_weatherman"
3
- gem.version = "0.9"
3
+ gem.version = "1.0.0"
4
4
  gem.authors = ["Dalto Curvelano Junior"]
5
5
  gem.description = "A ruby wrapper to the Yahoo! Weather feed with i18n support."
6
6
  gem.summary = "A ruby wrapper to the Yahoo! Weather feed with i18n support."
metadata CHANGED
@@ -3,9 +3,10 @@ name: yahoo_weatherman
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
+ - 1
6
7
  - 0
7
- - 9
8
- version: "0.9"
8
+ - 0
9
+ version: 1.0.0
9
10
  platform: ruby
10
11
  authors:
11
12
  - Dalto Curvelano Junior
@@ -13,7 +14,7 @@ autorequire:
13
14
  bindir: bin
14
15
  cert_chain: []
15
16
 
16
- date: 2010-04-28 00:00:00 -03:00
17
+ date: 2010-05-03 00:00:00 -03:00
17
18
  default_executable:
18
19
  dependencies: []
19
20