yahoo_weatherman 1.0.1 → 1.0.2
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 +41 -40
- data/lib/yahoo_weatherman/response.rb +4 -6
- data/lib/yahoo_weatherman.rb +7 -4
- data/spec/yahoo_weatherman/i18n_spec.rb +3 -1
- data/yahoo_weatherman.gemspec +12 -4
- metadata +3 -3
@@ -1,56 +1,57 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Weatherman
|
2
|
+
class I18N
|
3
|
+
I18N_YAML_DIR = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'i18n'))
|
3
4
|
|
4
|
-
|
5
|
+
LANGUAGES = {}
|
5
6
|
|
6
|
-
|
7
|
+
attr_accessor :language
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
def translate!(attributes)
|
13
|
-
if i18n?
|
14
|
-
translate_text! attributes
|
15
|
-
translate_days! attributes
|
16
|
-
translate_locations! attributes
|
9
|
+
def initialize(language)
|
10
|
+
@language = language
|
17
11
|
end
|
18
|
-
attributes
|
19
|
-
end
|
20
12
|
|
21
|
-
|
22
|
-
|
23
|
-
|
13
|
+
def translate!(attributes)
|
14
|
+
if i18n?
|
15
|
+
translate_text! attributes
|
16
|
+
translate_days! attributes
|
17
|
+
translate_locations! attributes
|
18
|
+
end
|
19
|
+
attributes
|
24
20
|
end
|
25
21
|
|
26
|
-
|
27
|
-
|
28
|
-
|
22
|
+
private
|
23
|
+
def translate_text!(attributes)
|
24
|
+
translate_attribute('text', attributes, language_translations, 'code')
|
25
|
+
end
|
29
26
|
|
30
|
-
|
31
|
-
|
32
|
-
|
27
|
+
def translate_days!(attributes)
|
28
|
+
translate_attribute('day', attributes, language_translations['forecasts']['days'])
|
29
|
+
end
|
30
|
+
|
31
|
+
def translate_locations!(attributes)
|
32
|
+
(%w(city country region) & attributes.keys).each do |key|
|
33
|
+
translate_attribute(key, attributes, language_translations['locations'])
|
34
|
+
end
|
33
35
|
end
|
34
|
-
end
|
35
36
|
|
36
|
-
|
37
|
-
|
37
|
+
def translate_attribute(name, attributes, translations, change_by = nil)
|
38
|
+
translation_key = attributes[(change_by || name)]
|
38
39
|
|
39
|
-
|
40
|
-
|
40
|
+
if attributes[name] and translations[translation_key]
|
41
|
+
attributes[name] = translations[translation_key]
|
42
|
+
end
|
41
43
|
end
|
42
|
-
end
|
43
44
|
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
def language_translations
|
46
|
+
LANGUAGES[language] ||= load_language_yaml!
|
47
|
+
end
|
47
48
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
49
|
+
def load_language_yaml!
|
50
|
+
YAML::load File.read(File.join(I18N_YAML_DIR, language + '.yml'))
|
51
|
+
end
|
52
52
|
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
def i18n?
|
54
|
+
!!@language
|
55
|
+
end
|
56
|
+
end
|
56
57
|
end
|
@@ -10,8 +10,8 @@ module Weatherman
|
|
10
10
|
attr_accessor :document_root
|
11
11
|
|
12
12
|
def initialize(raw, language = nil)
|
13
|
-
@document_root = Nokogiri::XML
|
14
|
-
@i18n = I18N.new(language)
|
13
|
+
@document_root = Nokogiri::XML(raw).xpath('rss/channel')
|
14
|
+
@i18n = Weatherman::I18N.new(language)
|
15
15
|
end
|
16
16
|
|
17
17
|
#
|
@@ -154,13 +154,11 @@ module Weatherman
|
|
154
154
|
end
|
155
155
|
|
156
156
|
def item_attribute(attr)
|
157
|
-
|
158
|
-
attribute(attr, item)
|
157
|
+
attribute(attr, document_root.xpath('item').first)
|
159
158
|
end
|
160
159
|
|
161
160
|
def geo_attribute(attr)
|
162
|
-
|
163
|
-
geo.children.first.text.to_f
|
161
|
+
item_attribute('geo:' + attr).children.first.text.to_f
|
164
162
|
end
|
165
163
|
|
166
164
|
def text_attribute(attr)
|
data/lib/yahoo_weatherman.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
path = File.expand_path(File.dirname(__FILE__))
|
2
2
|
$LOAD_PATH.unshift(path) unless $LOAD_PATH.include?(path)
|
3
3
|
|
4
|
+
require 'rubygems'
|
5
|
+
|
6
|
+
require 'yaml'
|
4
7
|
require 'open-uri'
|
5
8
|
require 'nokogiri'
|
6
|
-
require 'yaml'
|
7
9
|
|
8
10
|
require 'yahoo_weatherman/i18n'
|
9
11
|
require 'yahoo_weatherman/image'
|
@@ -11,7 +13,7 @@ require 'yahoo_weatherman/response'
|
|
11
13
|
|
12
14
|
module Weatherman
|
13
15
|
|
14
|
-
VERSION = '1.0.
|
16
|
+
VERSION = '1.0.2'
|
15
17
|
|
16
18
|
URI = 'http://weather.yahooapis.com/forecastrss'
|
17
19
|
|
@@ -35,6 +37,7 @@ module Weatherman
|
|
35
37
|
#
|
36
38
|
def initialize(options = {})
|
37
39
|
@options = options
|
40
|
+
@uri = options[:url] || URI
|
38
41
|
end
|
39
42
|
|
40
43
|
#
|
@@ -47,7 +50,7 @@ module Weatherman
|
|
47
50
|
|
48
51
|
private
|
49
52
|
def request_url(woeid)
|
50
|
-
|
53
|
+
@uri + query_string(woeid)
|
51
54
|
end
|
52
55
|
|
53
56
|
def query_string(woeid)
|
@@ -59,7 +62,7 @@ module Weatherman
|
|
59
62
|
end
|
60
63
|
|
61
64
|
def get(url)
|
62
|
-
open(url)
|
65
|
+
open(url).read
|
63
66
|
end
|
64
67
|
end
|
65
68
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe I18N do
|
3
|
+
describe Weatherman::I18N do
|
4
4
|
before do
|
5
5
|
@response = Weatherman::Client.new(:lang => 'pt-br').lookup_by_woeid 455821
|
6
6
|
end
|
@@ -11,6 +11,8 @@ describe I18N do
|
|
11
11
|
|
12
12
|
it 'should translate the location details' do
|
13
13
|
@response.location['country'].should == 'Brasil'
|
14
|
+
@response.location['city'].should == 'Santa Luzia'
|
15
|
+
@response.location['region'].should == 'Minas Gerais'
|
14
16
|
end
|
15
17
|
|
16
18
|
it 'should translate the forecasts details' do
|
data/yahoo_weatherman.gemspec
CHANGED
@@ -1,14 +1,22 @@
|
|
1
1
|
Gem::Specification.new do |gem|
|
2
2
|
gem.name = "yahoo_weatherman"
|
3
|
-
gem.version = "1.0.
|
3
|
+
gem.version = "1.0.2"
|
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",
|
10
|
-
"
|
11
|
-
"
|
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"
|
12
20
|
]
|
13
21
|
gem.homepage = "http://github.com/dlt/yahoo_weatherman"
|
14
22
|
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
|
+
- 2
|
9
|
+
version: 1.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Dalto Curvelano Junior
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-05-
|
17
|
+
date: 2010-05-06 00:00:00 -03:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|