yahoo_weatherman 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,56 +1,57 @@
1
- class I18N
2
- I18N_YAML_DIR = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'i18n'))
1
+ module Weatherman
2
+ class I18N
3
+ I18N_YAML_DIR = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'i18n'))
3
4
 
4
- LANGUAGES = {}
5
+ LANGUAGES = {}
5
6
 
6
- attr_accessor :language
7
+ attr_accessor :language
7
8
 
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
9
+ def initialize(language)
10
+ @language = language
17
11
  end
18
- attributes
19
- end
20
12
 
21
- private
22
- def translate_text!(attributes)
23
- translate_attribute('text', attributes, language_translations, 'code')
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
- def translate_days!(attributes)
27
- translate_attribute('day', attributes, language_translations['forecasts']['days'])
28
- end
22
+ private
23
+ def translate_text!(attributes)
24
+ translate_attribute('text', attributes, language_translations, 'code')
25
+ end
29
26
 
30
- def translate_locations!(attributes)
31
- (%w[city country region] & attributes.keys).each do |key|
32
- translate_attribute(key, attributes, language_translations['locations'])
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
- def translate_attribute(name, attributes, translations, change_by = nil)
37
- translation_key = attributes[(change_by || name)]
37
+ def translate_attribute(name, attributes, translations, change_by = nil)
38
+ translation_key = attributes[(change_by || name)]
38
39
 
39
- if attributes[name] and translations[translation_key]
40
- attributes[name] = translations[translation_key]
40
+ if attributes[name] and translations[translation_key]
41
+ attributes[name] = translations[translation_key]
42
+ end
41
43
  end
42
- end
43
44
 
44
- def language_translations
45
- LANGUAGES[language] ||= load_language_yaml!
46
- end
45
+ def language_translations
46
+ LANGUAGES[language] ||= load_language_yaml!
47
+ end
47
48
 
48
- def load_language_yaml!
49
- stream = File.read(File.join(I18N_YAML_DIR, language + '.yml'))
50
- YAML::load(stream)
51
- end
49
+ def load_language_yaml!
50
+ YAML::load File.read(File.join(I18N_YAML_DIR, language + '.yml'))
51
+ end
52
52
 
53
- def i18n?
54
- !!@language
55
- end
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.parse(raw).xpath('rss/channel')
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
- item = document_root.xpath('item').first
158
- attribute(attr, item)
157
+ attribute(attr, document_root.xpath('item').first)
159
158
  end
160
159
 
161
160
  def geo_attribute(attr)
162
- geo = item_attribute('geo:' + attr)
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)
@@ -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.1'
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
- URI + query_string(woeid)
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) { |stream| stream.read }
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
@@ -1,14 +1,22 @@
1
1
  Gem::Specification.new do |gem|
2
2
  gem.name = "yahoo_weatherman"
3
- gem.version = "1.0.1"
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", "lib/yahoo_weatherman/response.rb", "lib/yahoo_weatherman/i18n.rb", "lib/yahoo_weatherman.rb",
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", "spec/yahoo_weatherman/i18n_spec.rb"
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
- - 1
9
- version: 1.0.1
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-03 00:00:00 -03:00
17
+ date: 2010-05-06 00:00:00 -03:00
18
18
  default_executable:
19
19
  dependencies: []
20
20