yahoo_weatherman 1.0.0 → 1.0.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/yahoo_weatherman/i18n.rb +56 -0
- data/lib/yahoo_weatherman.rb +1 -1
- data/spec/yahoo_weatherman/i18n_spec.rb +24 -0
- data/yahoo_weatherman.gemspec +3 -3
- metadata +4 -2
@@ -0,0 +1,56 @@
|
|
1
|
+
class I18N
|
2
|
+
I18N_YAML_DIR = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'i18n'))
|
3
|
+
|
4
|
+
LANGUAGES = {}
|
5
|
+
|
6
|
+
attr_accessor :language
|
7
|
+
|
8
|
+
def initialize(language)
|
9
|
+
@language = language
|
10
|
+
end
|
11
|
+
|
12
|
+
def translate!(attributes)
|
13
|
+
if i18n?
|
14
|
+
translate_text! attributes
|
15
|
+
translate_days! attributes
|
16
|
+
translate_locations! attributes
|
17
|
+
end
|
18
|
+
attributes
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def translate_text!(attributes)
|
23
|
+
translate_attribute('text', attributes, language_translations, 'code')
|
24
|
+
end
|
25
|
+
|
26
|
+
def translate_days!(attributes)
|
27
|
+
translate_attribute('day', attributes, language_translations['forecasts']['days'])
|
28
|
+
end
|
29
|
+
|
30
|
+
def translate_locations!(attributes)
|
31
|
+
(%w[city country region] & attributes.keys).each do |key|
|
32
|
+
translate_attribute(key, attributes, language_translations['locations'])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def translate_attribute(name, attributes, translations, change_by = nil)
|
37
|
+
translation_key = attributes[(change_by || name)]
|
38
|
+
|
39
|
+
if attributes[name] and translations[translation_key]
|
40
|
+
attributes[name] = translations[translation_key]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def language_translations
|
45
|
+
LANGUAGES[language] ||= load_language_yaml!
|
46
|
+
end
|
47
|
+
|
48
|
+
def load_language_yaml!
|
49
|
+
stream = File.read(File.join(I18N_YAML_DIR, language + '.yml'))
|
50
|
+
YAML::load(stream)
|
51
|
+
end
|
52
|
+
|
53
|
+
def i18n?
|
54
|
+
!!@language
|
55
|
+
end
|
56
|
+
end
|
data/lib/yahoo_weatherman.rb
CHANGED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe I18N do
|
4
|
+
before do
|
5
|
+
@response = Weatherman::Client.new(:lang => 'pt-br').lookup_by_woeid 455821
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should translate the conditions details' do
|
9
|
+
@response.condition['text'].should == 'Predominantemente Nublado'
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should translate the location details' do
|
13
|
+
@response.location['country'].should == 'Brasil'
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should translate the forecasts details' do
|
17
|
+
@response.forecasts.first['text'].should == 'Chuva'
|
18
|
+
@response.forecasts.last['text'].should == 'Tempestades Intermitentes'
|
19
|
+
@response.forecasts.first['day'].should == 'Sábado'
|
20
|
+
@response.forecasts.last['day'].should == 'Domingo'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
|
data/yahoo_weatherman.gemspec
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = "yahoo_weatherman"
|
3
|
-
gem.version = "1.0.
|
3
|
+
gem.version = "1.0.1"
|
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."
|
7
7
|
gem.files = [
|
8
8
|
"yahoo_weatherman.gemspec",
|
9
|
-
"lib/yahoo_weatherman/image.rb", "lib/yahoo_weatherman/response.rb", "lib/yahoo_weatherman.rb",
|
9
|
+
"lib/yahoo_weatherman/image.rb", "lib/yahoo_weatherman/response.rb", "lib/yahoo_weatherman/i18n.rb", "lib/yahoo_weatherman.rb",
|
10
10
|
"i18n/pt-br.yml", "spec/files/belo_horizonte_c.rss", "spec/files/belo_horizonte_f.rss", "spec/spec_helper.rb",
|
11
|
-
"spec/yahoo_weatherman/response_spec.rb", "spec/yahoo_weatherman/yahoo_weatherman_spec.rb"
|
11
|
+
"spec/yahoo_weatherman/response_spec.rb", "spec/yahoo_weatherman/yahoo_weatherman_spec.rb", "spec/yahoo_weatherman/i18n_spec.rb"
|
12
12
|
]
|
13
13
|
gem.homepage = "http://github.com/dlt/yahoo_weatherman"
|
14
14
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
8
|
+
- 1
|
9
|
+
version: 1.0.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Dalto Curvelano Junior
|
@@ -30,6 +30,7 @@ files:
|
|
30
30
|
- yahoo_weatherman.gemspec
|
31
31
|
- lib/yahoo_weatherman/image.rb
|
32
32
|
- lib/yahoo_weatherman/response.rb
|
33
|
+
- lib/yahoo_weatherman/i18n.rb
|
33
34
|
- lib/yahoo_weatherman.rb
|
34
35
|
- i18n/pt-br.yml
|
35
36
|
- spec/files/belo_horizonte_c.rss
|
@@ -37,6 +38,7 @@ files:
|
|
37
38
|
- spec/spec_helper.rb
|
38
39
|
- spec/yahoo_weatherman/response_spec.rb
|
39
40
|
- spec/yahoo_weatherman/yahoo_weatherman_spec.rb
|
41
|
+
- spec/yahoo_weatherman/i18n_spec.rb
|
40
42
|
has_rdoc: true
|
41
43
|
homepage: http://github.com/dlt/yahoo_weatherman
|
42
44
|
licenses: []
|