weather_jp 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,103 @@
1
+ [![Build Status](https://secure.travis-ci.org/Taiki45/weather_jp.png?branch=master)](http://travis-ci.org/Taiki45/weather_jp)
2
+
3
+ ## About
4
+
5
+ 天気予報サービス API ラッパーです。
6
+
7
+ 天気予報を簡単に Ruby オブジェクトにします。
8
+
9
+ http://taiki45.github.com/weather_jp
10
+
11
+ https://rubygems.org/gems/weather_jp
12
+
13
+ ## インストール
14
+
15
+ この一行をあなたのアプリケーションの Gemfile に追記して下さい:
16
+
17
+ gem 'weather_jp'
18
+
19
+ そしてこう実行します:
20
+
21
+ $ bundle
22
+
23
+ または gem コマンドを使ってインストールします:
24
+
25
+ $ gem install weather_jp
26
+
27
+ ## 使い方
28
+
29
+ ```ruby
30
+ # 全体の天気予報を扱うオブジェクトを作るいくつかの方法
31
+ tokyo = WeatherJp.get :tokyo
32
+ akiba = WeatherJp.get "秋葉原"
33
+ abuja = WeatherJp::Weather.new("アブジャ")
34
+ tsuyama = WeatherJp.get "津山"
35
+
36
+ # 天気予報を文字列として取得
37
+ tokyo.today.to_s
38
+ #=> これは "東京都 東京の天気は曇りのち晴れ、最高気温34度...etc" になります
39
+
40
+ # Weather オブジェクトを取得するいくつかの方法
41
+ akiba.get_weather(4) #=> <#DayWeather object>
42
+ tokyo.today.forecast #=> can be "晴れ"
43
+ tokyo.get_weather(:tomorrow).rain
44
+ akiba.day_after_tomorrow.to_s
45
+ WeatherJp.get(:tokyo, :today).forecast
46
+
47
+ # Weather オブジェクトを使ってみる
48
+ tokyo.each do |w|
49
+ puts w.city_name
50
+ puts w.day
51
+ puts w.forecast
52
+ puts w.max_temp
53
+ puts w.min_temp
54
+ puts w.rain
55
+ w.each_pair {|k,v| puts k, v }
56
+ end
57
+
58
+ akiba.map {|w| [w.day, w.forecast] }
59
+
60
+ # もしくは単純な Array や Hash として扱う方法
61
+ tokyo.to_a
62
+ tsuyama.each {|w| p w.to_hash }
63
+ akiba.day_weathers
64
+
65
+ # DayWeather#to_s メソッドをカスタマイズすることもできます
66
+ WeatherJp.get(:tokyo).today.to_s #=> "東京 東京都の天気は晴れ....etc"
67
+
68
+ WeatherJp.customize_to_s do
69
+ word = "#{day}の#{city_name}は#{forecast} "
70
+ word << "最高気温は#{max_temp} " if max_temp
71
+ word << "最低気温は#{min_temp} " if min_temp
72
+ word << "降水確率は#{rain}%" if rain
73
+ word << "でし"
74
+ word
75
+ end
76
+
77
+ WeatherJp.get(:tokyo).today.to_s #=> "本日の東京 東京都は晴れ...."
78
+
79
+ ```
80
+
81
+ ## 必要な環境
82
+
83
+ Ruby >= 1.9.2
84
+
85
+ ## ドキュメント
86
+
87
+ http://rubydoc.info/gems/weather_jp/
88
+
89
+ ## 作者
90
+
91
+ [@taiki45](https://twitter.com/taiki45)
92
+
93
+ ## 貢献方法
94
+
95
+ 1. Fork してください
96
+ 2. あなたの機能を盛り込んだブランチを作って下さい (`git checkout -b my-new-feature`)
97
+ 3. コミットしてください (`git commit -am 'Added some feature'`)
98
+ 4. あなたの変更をプッシュしてください (`git push origin my-new-feature`)
99
+ 5. Pull Request を作ってください
100
+
101
+ どんな要望やバグ報告、イッシュー、コメントも歓迎します
102
+
103
+ Thank you :)
data/README.md CHANGED
@@ -28,20 +28,21 @@ Or install it yourself as:
28
28
 
29
29
  ```ruby
30
30
  # creat weather object in differrnt ways
31
- tokyo = WeatherJp.get :today
32
- tokyo = WeatherJp::Weather.new :tokyo
33
- minato = WeatherJp::Weather.new("東京都港区")
31
+ tokyo = WeatherJp.get :tokyo
32
+ akiba = WeatherJp.get "秋葉原"
33
+ abuja = WeatherJp::Weather.new("アブジャ")
34
+ tsuyama = WeatherJp.get "津山"
34
35
 
35
36
  # get weather info as String
36
37
  tokyo.today.to_s
37
38
  #=> can be "東京都 東京の天気は曇りのち晴れ、最高気温34度...etc"
38
39
 
39
40
  # to get weather info in differrnt ways
40
- minato.get_weather(4) #=> <#DayWeather object>
41
- minato.today.forecast #=> can be "晴れ"
41
+ akiba.get_weather(4) #=> <#DayWeather object>
42
+ tokyo.today.forecast #=> can be "晴れ"
42
43
  tokyo.get_weather(:tomorrow).rain
43
- minato.day_after_tomorrow.to_s
44
- Weather.get(:tokyo, :today).forecast
44
+ akiba.day_after_tomorrow.to_s
45
+ WeatherJp.get(:tokyo, :today).forecast
45
46
 
46
47
  # use Weather object
47
48
  tokyo.each do |w|
@@ -54,16 +55,17 @@ tokyo.each do |w|
54
55
  w.each_pair {|k,v| puts k, v }
55
56
  end
56
57
 
57
- minato.map {|w| [w.day, w.forecast] }
58
+ akiba.map {|w| [w.day, w.forecast] }
58
59
 
59
60
  # or use as simple Array or Hash
60
61
  tokyo.to_a
61
- minato.each {|w| p w.to_hash }
62
+ tsuyama.each {|w| p w.to_hash }
63
+ akiba.day_weathers
62
64
 
63
65
  # you can cutomize DayWeather#to_s method
64
- Weather.get(:tokyo).today.to_s #=> "東京 東京都の天気は晴れ....etc"
66
+ WeatherJp.get(:tokyo).today.to_s #=> "東京 東京都の天気は晴れ....etc"
65
67
 
66
- Weather.customize_to_s do
68
+ WeatherJp.customize_to_s do
67
69
  word = "#{day}の#{city_name}は#{forecast} "
68
70
  word << "最高気温は#{max_temp} " if max_temp
69
71
  word << "最低気温は#{min_temp} " if min_temp
@@ -72,7 +74,7 @@ Weather.customize_to_s do
72
74
  word
73
75
  end
74
76
 
75
- Weather.get(:tokyo).today.to_s #=> "本日の東京 東京都は晴れ...."
77
+ WeatherJp.get(:tokyo).today.to_s #=> "本日の東京 東京都は晴れ...."
76
78
 
77
79
  ```
78
80
 
@@ -84,6 +86,10 @@ Ruby >= 1.9.2
84
86
 
85
87
  http://rubydoc.info/gems/weather_jp/
86
88
 
89
+ ## Author
90
+
91
+ [@taiki45](https://twitter.com/taiki45)
92
+
87
93
  ## Contributing
88
94
 
89
95
  1. Fork it
@@ -95,4 +101,3 @@ http://rubydoc.info/gems/weather_jp/
95
101
  Feel free to any requests or bug reports, issues, comments.
96
102
 
97
103
  Thank you :)
98
-
@@ -114,22 +114,29 @@ module WeatherJp
114
114
 
115
115
 
116
116
  def get_weather_data
117
+ parse_rss(get_rss)
118
+ end
119
+
120
+ def get_rss
117
121
  begin
118
122
  uri = URI.parse(
119
123
  "http://weather.jp.msn.com/" + \
120
124
  "RSS.aspx?wealocations=wc:#{@area_code}&" + \
121
125
  "weadegreetype=C&culture=ja-JP")
122
- rss = RSS::Parser.parse(uri, false)
123
- str = rss.channel.item(0).description
124
- data = remove_html_tag(str).split(/%/)
125
- data.pop
126
- data.map {|i| i.delete!('"') }
126
+ RSS::Parser.parse(uri, false)
127
127
  rescue
128
128
  raise StandardError,
129
129
  "the MSN weather sever may be downed, or got invaild city code"
130
130
  end
131
131
  end
132
132
 
133
+ def parse_rss(rss)
134
+ str = rss.channel.item(0).description
135
+ data = remove_html_tag(str).split(/%/)
136
+ data.pop
137
+ data.map {|i| i.delete!('"') }
138
+ end
139
+
133
140
  def remove_html_tag(string)
134
141
  string.gsub!(/<(\"[^\"]*\"|'[^']*'|[^'\">])*>/,'""')
135
142
  end
@@ -1,3 +1,3 @@
1
1
  module WeatherJp
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -22,8 +22,6 @@ describe "DayWeather" do
22
22
  it "should return String" do
23
23
  @weather.inspect.class.should == String
24
24
  end
25
-
26
- it "should have certain format"
27
25
  end
28
26
 
29
27
  describe "#to_s" do
@@ -31,7 +29,9 @@ describe "DayWeather" do
31
29
  @weather.to_s.class.should == String
32
30
  end
33
31
 
34
- it "should be certain string when certain environment"
32
+ it "should be certain string format" do
33
+ @weather.to_s.should =~ /東京都\s東京の今日の天気は.*\sです。/u
34
+ end
35
35
  end
36
36
 
37
37
  describe "#to_hash" do
@@ -45,8 +45,6 @@ describe "DayWeather" do
45
45
  @weather.to_hash.should have_key(:max_temp)
46
46
  @weather.to_hash.should have_key(:rain)
47
47
  end
48
-
49
- it "should have certain value when certain env"
50
48
  end
51
49
 
52
50
  describe "#each" do
@@ -0,0 +1 @@
1
+ <?xml version="1.0" ?><?xml-stylesheet type='text/xsl' href='rss/xslt/rss-ja-JP.xsl' version='1.0'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>東京都 東京 - MSN 天気予報</title><link>http://weather.jp.msn.com/local.aspx?wealocations=wc:JAXX0085&amp;q=%e6%9d%b1%e4%ba%ac%e9%83%bd+%e6%9d%b1%e4%ba%ac&amp;src=rss</link><description>東京都 東京 の天気予報</description><image><url>http://kaw.stc.s-msn.com/as/wea3/i/ja/weather_h_pos_c_171x30.gif</url><title>MSN 天気予報</title><link>http://weather.jp.msn.com/default.aspx?src=rss</link></image><language>ja-JP</language><category>天気</category><ttl>60</ttl><lastBuildDate>Sat, 29 Sep 2012 16:00:00 GMT</lastBuildDate><generator>MSN 天気予報</generator><copyright>© 2012 Microsoft</copyright><item><title>東京都 東京 の 2012年9月30日 の天気予報</title><link>http://weather.jp.msn.com/local.aspx?wealocations=wc:JAXX0085&amp;q=%e6%9d%b1%e4%ba%ac%e9%83%bd+%e6%9d%b1%e4%ba%ac&amp;src=rss</link><pubDate>Sat, 29 Sep 2012 08:00:00 GMT</pubDate><guid isPermaLink="false">GUID:http://weather.msn.com/rss.aspx?wealocations=wc:JAXX0085&amp;q=%e6%9d%b1%e4%ba%ac%e9%83%bd+%e6%9d%b1%e4%ba%ac&amp;degreetype=C&amp;ja-JP+Sat, 29 Sep 2012 08:00:00 GMT+FORECAST</guid><description><![CDATA[<p><strong><a href="http://weather.jp.msn.com/local.aspx?wealocations=wc:JAXX0085&amp;q=%e6%9d%b1%e4%ba%ac%e9%83%bd+%e6%9d%b1%e4%ba%ac&amp;src=rss">今日</a>: </strong>晴のち雨.<img src="http://kaw.stc.s-msn.com/as/wea3/i/ja/saw/61.gif" width="35" height="21" alt="晴のち雨" title="晴のち雨" /> 最低: 24&#176;C. 最高: 29&#176;C. 降水確率: 80%<br /><strong><a href="http://weather.jp.msn.com/local.aspx?wealocations=wc:JAXX0085&amp;q=%e6%9d%b1%e4%ba%ac%e9%83%bd+%e6%9d%b1%e4%ba%ac&amp;src=rss">明日</a>: </strong>雨のち晴.<img src="http://kaw.stc.s-msn.com/as/wea3/i/ja/saw/66.gif" width="35" height="21" alt="雨のち晴" title="雨のち晴" /> 最低: 22&#176;C. 最高: 30&#176;C. 降水確率: 60%<br /><strong><a href="http://weather.jp.msn.com/local.aspx?wealocations=wc:JAXX0085&amp;q=%e6%9d%b1%e4%ba%ac%e9%83%bd+%e6%9d%b1%e4%ba%ac&amp;src=rss">火曜日</a>: </strong>曇時々晴.<img src="http://kaw.stc.s-msn.com/as/wea3/i/ja/saw/51.gif" width="35" height="21" alt="曇時々晴" title="曇時々晴" /> 最低: 22&#176;C. 最高: 27&#176;C. 降水確率: 30%<br /><strong><a href="http://weather.jp.msn.com/local.aspx?wealocations=wc:JAXX0085&amp;q=%e6%9d%b1%e4%ba%ac%e9%83%bd+%e6%9d%b1%e4%ba%ac&amp;src=rss">水曜日</a>: </strong>曇時々雨.<img src="http://kaw.stc.s-msn.com/as/wea3/i/ja/saw/52.gif" width="35" height="21" alt="曇時々雨" title="曇時々雨" /> 最低: 20&#176;C. 最高: 25&#176;C. 降水確率: 50%<br /><strong><a href="http://weather.jp.msn.com/local.aspx?wealocations=wc:JAXX0085&amp;q=%e6%9d%b1%e4%ba%ac%e9%83%bd+%e6%9d%b1%e4%ba%ac&amp;src=rss">木曜日</a>: </strong>曇り.<img src="http://kaw.stc.s-msn.com/as/wea3/i/ja/saw/26.gif" width="35" height="21" alt="曇り" title="曇り" /> 最低: 20&#176;C. 最高: 28&#176;C. 降水確率: 40%<br /></p><p><a href="http://weather.jp.msn.com/local.aspx?wealocations=wc:JAXX0085&amp;q=%e6%9d%b1%e4%ba%ac%e9%83%bd+%e6%9d%b1%e4%ba%ac&amp;src=rss">MSN 天気予報でもっと情報を見る</a><br />(Foreca 提供データ (米国およびカナダ以外), WDT 提供データ (米国およびカナダ向け))</p>]]></description></item></channel></rss>
@@ -5,3 +5,13 @@ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
5
5
  require 'rubygems'
6
6
  require 'nokogiri'
7
7
  require 'weather_jp'
8
+
9
+ def fixture_path
10
+ File.expand_path('../fixture/', __FILE__)
11
+ end
12
+
13
+ def rss_one
14
+ file = open(fixture_path + '/RSS.rss')
15
+ yield file.read
16
+ file.close
17
+ end
@@ -3,149 +3,183 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe "Weather" do
6
- before(:all) do
7
- @weather = WeatherJp::Weather.new(:tokyo)
8
- end
9
-
10
- describe "#initialize" do
11
- it "should have @area_code and can access" do
12
- @weather.area_code.should == "JAXX0085"
13
- end
14
-
15
- it "should have @city_name and can access" do
16
- @weather.city_name.should == "東京都 東京"
6
+ describe "with Internet connetion" do
7
+ before(:all) do
8
+ @weather = WeatherJp::Weather.new(:tokyo)
17
9
  end
18
10
 
19
- it "should accept String argument" do
20
- weather = WeatherJp::Weather.new "東京都府中市"
21
- weather.city_name.should == "東京都 府中市"
22
- end
11
+ describe "#initialize" do
12
+ it "should have @area_code and can access" do
13
+ @weather.area_code.should == "JAXX0085"
14
+ end
23
15
 
24
- it "should accept Symbol argument" do
25
- weather = WeatherJp::Weather.new :tokyo
26
- weather.city_name.should == "東京都 東京"
27
- end
16
+ it "should have @city_name and can access" do
17
+ @weather.city_name.should == "東京都 東京"
18
+ end
28
19
 
29
- it "should have @day_weathers as Array" do
30
- @weather.day_weathers.class.should == Array
31
- end
20
+ it "should accept String argument" do
21
+ weather = WeatherJp::Weather.new "東京都府中市"
22
+ weather.city_name.should == "東京都 府中市"
23
+ end
32
24
 
33
- it "should have DayWeather instance in @day_weathers" do
34
- @weather.day_weathers.each do |w|
35
- w.class.should == WeatherJp::Weather::DayWeather
25
+ it "should accept Symbol argument" do
26
+ weather = WeatherJp::Weather.new :tokyo
27
+ weather.city_name.should == "東京都 東京"
36
28
  end
37
- end
38
29
 
39
- it "should have 5 DayWeather instance in @day_weathers" do
40
- @weather.day_weathers.size.should == 5
41
- end
42
- end
30
+ it "should have @day_weathers as Array" do
31
+ @weather.day_weathers.class.should == Array
32
+ end
43
33
 
44
- describe "#get_area_code" do
45
- it "should get vaild area code" do
46
- @weather.area_code.should == "JAXX0085"
47
- end
34
+ it "should have DayWeather instance in @day_weathers" do
35
+ @weather.day_weathers.each do |w|
36
+ w.class.should == WeatherJp::Weather::DayWeather
37
+ end
38
+ end
48
39
 
49
- it "should raise error when invaild city name taken" do
50
- ->(){ WeatherJp::Weather.new(:aaa) }.should raise_error ArgumentError
40
+ it "should have 5 DayWeather instance in @day_weathers" do
41
+ @weather.day_weathers.size.should == 5
42
+ end
51
43
  end
52
- end
53
-
54
- describe "#get_weather_data" do
55
- it "should vaild unprocessing weather data"
56
-
57
- it "should raise StandardError when server connection is lost"
58
- end
59
44
 
60
- describe "#remove_html_tag" do
61
- it "should remove html tags"
62
- end
45
+ describe "#get_area_code" do
46
+ it "should get vaild area code" do
47
+ @weather.area_code.should == "JAXX0085"
48
+ end
63
49
 
64
- describe "#to_hash" do
65
- it "should return Array and include Hashs" do
66
- @weather.to_hash.class.should == Array
67
- @weather.to_hash.each {|e| e.class.should == Hash }
50
+ it "should raise error when invaild city name taken" do
51
+ WeatherJp::Weather.new(:aaa).city_name.should == "アメリカ合衆国 マイアミ"
52
+ end
68
53
  end
69
54
 
70
- it "should return with vaild structure" do
71
- @weather.to_hash.each do |e|
72
- e.should have_key(:day)
73
- e.should have_key(:forecast)
74
- e.should have_key(:max_temp)
75
- e.should have_key(:rain)
55
+ describe "#to_hash" do
56
+ it "should return Array and include Hashs" do
57
+ @weather.to_hash.class.should == Array
58
+ @weather.to_hash.each {|e| e.class.should == Hash }
76
59
  end
77
- end
78
- end
79
60
 
80
- describe "#to_a" do
81
- it "should return and behavior same as #to_hash" do
82
- @weather.to_a.should equal(@weather.to_hash)
61
+ it "should return with vaild structure" do
62
+ @weather.to_hash.each do |e|
63
+ e.should have_key(:day)
64
+ e.should have_key(:forecast)
65
+ e.should have_key(:max_temp)
66
+ e.should have_key(:rain)
67
+ end
68
+ end
83
69
  end
84
- end
85
70
 
86
- describe "#each" do
87
- it "should yield DayWeather object" do
88
- @weather.each {|w| w.class.should == WeatherJp::Weather::DayWeather }
71
+ describe "#to_a" do
72
+ it "should return and behavior same as #to_hash" do
73
+ @weather.to_a.should equal(@weather.to_hash)
74
+ end
89
75
  end
90
- end
91
76
 
92
- describe "Enumerable mehods" do
93
- it "should respond to Enumerable methods" do
94
- @weather.should respond_to(:map)
77
+ describe "#each" do
78
+ it "should yield DayWeather object" do
79
+ @weather.each {|w| w.class.should == WeatherJp::Weather::DayWeather }
80
+ end
95
81
  end
96
82
 
97
- it "should yield DayWeather Object" do
98
- @weather.map {|w| w.class.should == WeatherJp::Weather::DayWeather }
99
- end
100
- end
83
+ describe "Enumerable mehods" do
84
+ it "should respond to Enumerable methods" do
85
+ @weather.should respond_to(:map)
86
+ end
101
87
 
102
- describe "#get_weather" do
103
- it "should accept Symbol argument" do
104
- ->(){ @weather.get_weather(:today) }.
105
- should_not raise_error(ArgumentError)
106
- ->(){ @weather.get_weather(:tomorrow) }.
107
- should_not raise_error(ArgumentError)
88
+ it "should yield DayWeather Object" do
89
+ @weather.map {|w| w.class.should == WeatherJp::Weather::DayWeather }
90
+ end
108
91
  end
109
92
 
110
- it "should accept String argument" do
111
- ->(){ @weather.get_weather('today') }.
112
- should_not raise_error(ArgumentError)
113
- ->(){ @weather.get_weather('tomorrow') }.
114
- should_not raise_error(ArgumentError)
115
- end
93
+ describe "#get_weather" do
94
+ it "should accept Symbol argument" do
95
+ ->(){ @weather.get_weather(:today) }.
96
+ should_not raise_error(ArgumentError)
97
+ ->(){ @weather.get_weather(:tomorrow) }.
98
+ should_not raise_error(ArgumentError)
99
+ end
116
100
 
117
- it "should accept 0 to 4 number as argument" do
118
- (0..4).each do |n|
119
- ->(){ @weather.get_weather(n) }.
101
+ it "should accept String argument" do
102
+ ->(){ @weather.get_weather('today') }.
103
+ should_not raise_error(ArgumentError)
104
+ ->(){ @weather.get_weather('tomorrow') }.
120
105
  should_not raise_error(ArgumentError)
121
106
  end
122
- end
123
107
 
124
- it "should raise ArgumentError when got invaild aregument" do
125
- ->(){ @weather.get_weather(:yesterday) }.
126
- should raise_error(ArgumentError)
127
- ->(){ @weather.get_weather(5) }.
128
- should raise_error(ArgumentError)
108
+ it "should accept 0 to 4 number as argument" do
109
+ (0..4).each do |n|
110
+ ->(){ @weather.get_weather(n) }.
111
+ should_not raise_error(ArgumentError)
112
+ end
113
+ end
114
+
115
+ it "should raise ArgumentError when got invaild aregument" do
116
+ ->(){ @weather.get_weather(:yesterday) }.
117
+ should raise_error(ArgumentError)
118
+ ->(){ @weather.get_weather(5) }.
119
+ should raise_error(ArgumentError)
120
+ end
121
+
122
+ it "should return DayWeather object" do
123
+ @weather.get_weather(0).class.
124
+ should == WeatherJp::Weather::DayWeather
125
+ end
129
126
  end
130
127
 
131
- it "should return DayWeather object" do
132
- @weather.get_weather(0).class.
133
- should == WeatherJp::Weather::DayWeather
128
+ describe "#today, #tomorrow, #day_after_tomorrow" do
129
+ it "should not error when call #today or something" do
130
+ %w(today tomorrow day_after_tomorrow).each do |s|
131
+ ->(){ @weather.send(s.to_sym) }.
132
+ should_not raise_error(NoMethodError)
133
+ end
134
+ end
135
+
136
+ it "should return DayWeather object" do
137
+ %w(today tomorrow day_after_tomorrow).each do |s|
138
+ @weather.send(s.to_sym).class.
139
+ should == WeatherJp::Weather::DayWeather
140
+ end
141
+ end
134
142
  end
135
143
  end
136
-
137
- describe "#today, #tomorrow, #day_after_tomorrow" do
138
- it "should not error when call #today or something" do
139
- %w(today tomorrow day_after_tomorrow).each do |s|
140
- ->(){ @weather.send(s.to_sym) }.
141
- should_not raise_error(NoMethodError)
144
+
145
+ describe "with fixtures" do
146
+ before(:all) do
147
+ dummy = ''
148
+ rss_one {|rss| dummy = RSS::Parser.parse rss }
149
+ WeatherJp::Weather.class_exec dummy do |dummy|
150
+ define_method(:get_area_code) {|city_name| ["JAXX0085", 'tokyo'] }
151
+ define_method(:get_rss) { dummy }
152
+ end
153
+ @weather = WeatherJp::Weather.new(:tokyo)
154
+ end
155
+
156
+ describe "#set_weathers" do
157
+ it "should have vaild data" do
158
+ expect = [{:day=>"今日", :forecast=>"晴のち雨", :max_temp=>"29", :min_temp=>"24", :rain=>"80"},
159
+ {:day=>"明日", :forecast=>"雨のち晴", :max_temp=>"30", :min_temp=>"22", :rain=>"60"},
160
+ {:day=>"火曜日", :forecast=>"曇時々晴", :max_temp=>"27", :min_temp=>"22", :rain=>"30"},
161
+ {:day=>"水曜日", :forecast=>"曇時々雨", :max_temp=>"25", :min_temp=>"20", :rain=>"50"},
162
+ {:day=>"木曜日", :forecast=>"曇り", :max_temp=>"28", :min_temp=>"20", :rain=>"40"}
163
+ ]
164
+ @weather.to_hash.should == expect
142
165
  end
143
166
  end
144
167
 
145
- it "should return DayWeather object" do
146
- %w(today tomorrow day_after_tomorrow).each do |s|
147
- @weather.send(s.to_sym).class.
148
- should == WeatherJp::Weather::DayWeather
168
+ describe "#get_weather_data" do
169
+ describe "#parse_rss" do
170
+ it "should parse rss data" do
171
+ expect = ["今日: 晴のち雨. 最低: 24&#176;C. 最高: 29&#176;C. 降水確率: 80", "明日: 雨のち晴. 最低: 22&#176;C. 最高: 30&#176;C. 降水確率: 60", "火曜日: 曇時々晴. 最低: 22&#176;C. 最高: 27&#176;C. 降水確率: 30", "水曜日: 曇時々雨. 最低: 20&#176;C. 最高: 25&#176;C. 降水確率: 50", "木曜日: 曇り. 最低: 20&#176;C. 最高: 28&#176;C. 降水確率: 40"]
172
+ rss_one do |rss|
173
+ @weather.send(:parse_rss, RSS::Parser.parse(rss)).should == expect
174
+ end
175
+ end
176
+ end
177
+
178
+ describe "#remove_html_tag" do
179
+ it "should remove html tags" do
180
+ data = %q(<html>a<a href="dummy">b</a><span>c</sapan></html>)
181
+ @weather.send(:remove_html_tag, data).should == %(""a""b""""c"""")
182
+ end
149
183
  end
150
184
  end
151
185
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weather_jp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-04 00:00:00.000000000 Z
12
+ date: 2012-09-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -86,12 +86,14 @@ files:
86
86
  - .travis.yml
87
87
  - Gemfile
88
88
  - LICENSE
89
+ - README.jp.md
89
90
  - README.md
90
91
  - Rakefile
91
92
  - lib/weather_jp.rb
92
93
  - lib/weather_jp/day_weather.rb
93
94
  - lib/weather_jp/version.rb
94
95
  - spec/day_weather_spec.rb
96
+ - spec/fixture/RSS.rss
95
97
  - spec/spec_helper.rb
96
98
  - spec/weather_jp_spec.rb
97
99
  - spec/weather_spec.rb
@@ -110,7 +112,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
110
112
  version: '0'
111
113
  segments:
112
114
  - 0
113
- hash: 21516764662165991
115
+ hash: 113366814983018964
114
116
  required_rubygems_version: !ruby/object:Gem::Requirement
115
117
  none: false
116
118
  requirements:
@@ -119,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
121
  version: '0'
120
122
  segments:
121
123
  - 0
122
- hash: 21516764662165991
124
+ hash: 113366814983018964
123
125
  requirements: []
124
126
  rubyforge_project:
125
127
  rubygems_version: 1.8.23
@@ -128,6 +130,7 @@ specification_version: 3
128
130
  summary: Japan weather info API wrapper.
129
131
  test_files:
130
132
  - spec/day_weather_spec.rb
133
+ - spec/fixture/RSS.rss
131
134
  - spec/spec_helper.rb
132
135
  - spec/weather_jp_spec.rb
133
136
  - spec/weather_spec.rb