weather_jp 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/weather_jp/version.rb +1 -1
- data/lib/weather_jp.rb +3 -0
- data/spec/fixture/ny.rss +33 -0
- data/spec/spec_helper.rb +7 -1
- data/spec/wrapper_spec.rb +25 -3
- metadata +6 -4
data/lib/weather_jp/version.rb
CHANGED
data/lib/weather_jp.rb
CHANGED
@@ -182,6 +182,9 @@ module WeatherJp
|
|
182
182
|
h[:max_temp] = i.slice(/(最高).*?(\d+)/u, 2)
|
183
183
|
h[:min_temp] = i.slice(/(最低).*?(\d+)/u, 2)
|
184
184
|
h[:rain] = i.slice(/(降水確率).*?(\d+)/u, 2)
|
185
|
+
if h[:day].match /の天気/u
|
186
|
+
h[:day] = h[:day].slice /(.*)の天気/u, 1
|
187
|
+
end
|
185
188
|
weathers << h
|
186
189
|
end
|
187
190
|
weathers
|
data/spec/fixture/ny.rss
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
<?xml-stylesheet type='text/xsl' href='rss/xslt/rss-ja-JP.xsl' version='1.0'?>
|
2
|
+
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
|
3
|
+
<channel>
|
4
|
+
<title>アメリカ合衆国 ニューヨーク - MSN 天気予報</title>
|
5
|
+
<link>http://weather.jp.msn.com/local.aspx?wealocations=wc:USNY0996&q=%e3%82%a2%e3%83%a1%e3%83%aa%e3%82%ab%e5%90%88%e8%a1%86%e5%9b%bd+%e3%83%8b%e3%83%a5%e3%83%bc%e3%83%a8%e3%83%bc%e3%82%af&src=rss</link>
|
6
|
+
<description>アメリカ合衆国 ニューヨーク の天気予報</description>
|
7
|
+
<image>
|
8
|
+
<url>http://kaw.stc.s-msn.com/as/wea3/i/ja/weather_h_pos_c_171x30.gif</url>
|
9
|
+
<title>MSN 天気予報</title>
|
10
|
+
<link>http://weather.jp.msn.com/default.aspx?src=rss</link>
|
11
|
+
</image>
|
12
|
+
<language>ja-JP</language>
|
13
|
+
<category>天気</category>
|
14
|
+
<ttl>60</ttl>
|
15
|
+
<lastBuildDate>Mon, 08 Oct 2012 09:51:00 GMT</lastBuildDate>
|
16
|
+
<generator>MSN 天気予報</generator>
|
17
|
+
<copyright>© 2012 Microsoft</copyright>
|
18
|
+
<item>
|
19
|
+
<title>現在の天気: アメリカ合衆国 ニューヨークの晴れ (5時51分 2012年10月8日)</title>
|
20
|
+
<link>http://weather.jp.msn.com/local.aspx?wealocations=wc:USNY0996&q=%e3%82%a2%e3%83%a1%e3%83%aa%e3%82%ab%e5%90%88%e8%a1%86%e5%9b%bd+%e3%83%8b%e3%83%a5%e3%83%bc%e3%83%a8%e3%83%bc%e3%82%af&src=rss</link>
|
21
|
+
<pubDate>Mon, 08 Oct 2012 09:51:00 GMT</pubDate>
|
22
|
+
<guid isPermaLink="false">GUID:http://weather.msn.com/rss.aspx?wealocations=wc:USNY0996&q=%e3%82%a2%e3%83%a1%e3%83%aa%e3%82%ab%e5%90%88%e8%a1%86%e5%9b%bd+%e3%83%8b%e3%83%a5%e3%83%bc%e3%83%a8%e3%83%bc%e3%82%af&degreetype=C&ja-JP+Mon, 08 Oct 2012 09:51:00 GMT+CONDITIONS</guid>
|
23
|
+
<description><![CDATA[<p><strong>現在の天気: (5時51分 現在)</strong><br /><img src="http://kaw.stc.s-msn.com/as/wea3/i/ja/law/31.gif" width="55" height="45" alt="晴れ" title="晴れ" /><br />晴れ. 7°C (体感気温 8). 湿度: 89% 風速: 風向: 西北西 / 風速: 2 m/s.<br />アメリカ合衆国 ニューヨーク の現地時刻で表示<br /><a href="http://weather.jp.msn.com/tenday.aspx?wealocations=wc:USNY0996&q=%e3%82%a2%e3%83%a1%e3%83%aa%e3%82%ab%e5%90%88%e8%a1%86%e5%9b%bd+%e3%83%8b%e3%83%a5%e3%83%bc%e3%83%a8%e3%83%bc%e3%82%af&src=rss">10 日間予報の詳細</a> <a href="http://weather.jp.msn.com/hourly.aspx?wealocations=wc:USNY0996&q=%e3%82%a2%e3%83%a1%e3%83%aa%e3%82%ab%e5%90%88%e8%a1%86%e5%9b%bd+%e3%83%8b%e3%83%a5%e3%83%bc%e3%83%a8%e3%83%bc%e3%82%af&src=rss">時間毎の予報</a> <a href="http://weather.jp.msn.com/localmaps.aspx?wealocations=wc:USNY0996&q=%e3%82%a2%e3%83%a1%e3%83%aa%e3%82%ab%e5%90%88%e8%a1%86%e5%9b%bd+%e3%83%8b%e3%83%a5%e3%83%bc%e3%83%a8%e3%83%bc%e3%82%af&src=rss">天気画像</a> <a href="http://weather.jp.msn.com/monthly_averages.aspx?wealocations=wc:USNY0996&q=%e3%82%a2%e3%83%a1%e3%83%aa%e3%82%ab%e5%90%88%e8%a1%86%e5%9b%bd+%e3%83%8b%e3%83%a5%e3%83%bc%e3%83%a8%e3%83%bc%e3%82%af&src=rss">【平均値と観測史上の記録】 気温・降水量</a> </p>]]></description>
|
24
|
+
</item>
|
25
|
+
<item>
|
26
|
+
<title>アメリカ合衆国 ニューヨーク の 2012年10月8日 の天気予報</title>
|
27
|
+
<link>http://weather.jp.msn.com/local.aspx?wealocations=wc:USNY0996&q=%e3%82%a2%e3%83%a1%e3%83%aa%e3%82%ab%e5%90%88%e8%a1%86%e5%9b%bd+%e3%83%8b%e3%83%a5%e3%83%bc%e3%83%a8%e3%83%bc%e3%82%af&src=rss</link>
|
28
|
+
<pubDate>Mon, 08 Oct 2012 09:00:00 GMT</pubDate>
|
29
|
+
<guid isPermaLink="false">GUID:http://weather.msn.com/rss.aspx?wealocations=wc:USNY0996&q=%e3%82%a2%e3%83%a1%e3%83%aa%e3%82%ab%e5%90%88%e8%a1%86%e5%9b%bd+%e3%83%8b%e3%83%a5%e3%83%bc%e3%83%a8%e3%83%bc%e3%82%af&degreetype=C&ja-JP+Mon, 08 Oct 2012 09:00:00 GMT+FORECAST</guid>
|
30
|
+
<description><![CDATA[<p><strong><a href="http://weather.jp.msn.com/tenday.aspx?wealocations=wc:USNY0996&q=%e3%82%a2%e3%83%a1%e3%83%aa%e3%82%ab%e5%90%88%e8%a1%86%e5%9b%bd+%e3%83%8b%e3%83%a5%e3%83%bc%e3%83%a8%e3%83%bc%e3%82%af&src=rss">今日</a>: </strong>曇時々晴.<img src="http://kaw.stc.s-msn.com/as/wea3/i/ja/saw/28.gif" width="35" height="21" alt="曇時々晴" title="曇時々晴" /> 最低: 9°C. 最高: 17°C. 降水確率: 0%<br /><strong><a href="http://weather.jp.msn.com/tenday.aspx?wealocations=wc:USNY0996&q=%e3%82%a2%e3%83%a1%e3%83%aa%e3%82%ab%e5%90%88%e8%a1%86%e5%9b%bd+%e3%83%8b%e3%83%a5%e3%83%bc%e3%83%a8%e3%83%bc%e3%82%af&src=rss">明日</a>: </strong>雨.<img src="http://kaw.stc.s-msn.com/as/wea3/i/ja/saw/11.gif" width="35" height="21" alt="雨" title="雨" /> 最低: 15°C. 最高: 16°C. 降水確率: 40%<br /><strong><a href="http://weather.jp.msn.com/tenday.aspx?wealocations=wc:USNY0996&q=%e3%82%a2%e3%83%a1%e3%83%aa%e3%82%ab%e5%90%88%e8%a1%86%e5%9b%bd+%e3%83%8b%e3%83%a5%e3%83%bc%e3%83%a8%e3%83%bc%e3%82%af&src=rss">水曜日</a>: </strong>雨.<img src="http://kaw.stc.s-msn.com/as/wea3/i/ja/saw/11.gif" width="35" height="21" alt="雨" title="雨" /> 最低: 11°C. 最高: 18°C. 降水確率: 20%<br /><strong><a href="http://weather.jp.msn.com/tenday.aspx?wealocations=wc:USNY0996&q=%e3%82%a2%e3%83%a1%e3%83%aa%e3%82%ab%e5%90%88%e8%a1%86%e5%9b%bd+%e3%83%8b%e3%83%a5%e3%83%bc%e3%83%a8%e3%83%bc%e3%82%af&src=rss">木曜日</a>: </strong>晴れ.<img src="http://kaw.stc.s-msn.com/as/wea3/i/ja/saw/32.gif" width="35" height="21" alt="晴れ" title="晴れ" /> 最低: 11°C. 最高: 17°C. 降水確率: 0%<br /><strong><a href="http://weather.jp.msn.com/tenday.aspx?wealocations=wc:USNY0996&q=%e3%82%a2%e3%83%a1%e3%83%aa%e3%82%ab%e5%90%88%e8%a1%86%e5%9b%bd+%e3%83%8b%e3%83%a5%e3%83%bc%e3%83%a8%e3%83%bc%e3%82%af&src=rss">金曜日</a>: </strong>雨.<img src="http://kaw.stc.s-msn.com/as/wea3/i/ja/saw/11.gif" width="35" height="21" alt="雨" title="雨" /> 最低: 9°C. 最高: 17°C. 降水確率: 20%<br /></p><p><a href="http://weather.jp.msn.com/local.aspx?wealocations=wc:USNY0996&q=%e3%82%a2%e3%83%a1%e3%83%aa%e3%82%ab%e5%90%88%e8%a1%86%e5%9b%bd+%e3%83%8b%e3%83%a5%e3%83%bc%e3%83%a8%e3%83%bc%e3%82%af&src=rss">MSN 天気予報でもっと情報を見る</a><br />(Foreca 提供データ (米国およびカナダ以外), WDT 提供データ (米国およびカナダ向け))</p>]]></description>
|
31
|
+
</item>
|
32
|
+
</channel>
|
33
|
+
</rss>
|
data/spec/spec_helper.rb
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
$LOAD_PATH.unshift File.expand_path("../", __FILE__)
|
3
3
|
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
4
4
|
|
5
|
-
require 'rubygems'
|
6
5
|
require 'nokogiri'
|
7
6
|
require 'weather_jp'
|
8
7
|
|
@@ -30,3 +29,10 @@ def get_dummy_rss
|
|
30
29
|
rss
|
31
30
|
end
|
32
31
|
|
32
|
+
def get_ny_rss
|
33
|
+
rss = ''
|
34
|
+
open fixture_path + '/ny.rss' do |file|
|
35
|
+
rss = RSS::Parser.parse file.read
|
36
|
+
end
|
37
|
+
rss
|
38
|
+
end
|
data/spec/wrapper_spec.rb
CHANGED
@@ -10,17 +10,39 @@ describe "Wrapper" do
|
|
10
10
|
{:day=>"水曜日", :forecast=>"曇時々雨", :max_temp=>"25", :min_temp=>"20", :rain=>"50"},
|
11
11
|
{:day=>"木曜日", :forecast=>"曇り", :max_temp=>"28", :min_temp=>"20", :rain=>"40"}
|
12
12
|
]
|
13
|
-
dummy_data = ["今日: 晴のち雨. 最低: 24°C. 最高: 29°C. 降水確率: 80",
|
14
|
-
|
13
|
+
dummy_data = ["今日: 晴のち雨. 最低: 24°C. 最高: 29°C. 降水確率: 80",
|
14
|
+
"明日: 雨のち晴. 最低: 22°C. 最高: 30°C. 降水確率: 60",
|
15
|
+
"火曜日: 曇時々晴. 最低: 22°C. 最高: 27°C. 降水確率: 30",
|
16
|
+
"水曜日: 曇時々雨. 最低: 20°C. 最高: 25°C. 降水確率: 50",
|
17
|
+
"木曜日: 曇り. 最低: 20°C. 最高: 28°C. 降水確率: 40"
|
18
|
+
]
|
19
|
+
WeatherJp::Wrapper.set_weathers(dummy_data).should == expect
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should parse non-japan weather info" do
|
23
|
+
#expect = [{:day=>"現在の天気", :forecast=>"(5時51分 現在)晴れ", :max_temp=>nil, :min_temp=>nil, :rain=>nil}]
|
24
|
+
expect = [{:day=>"現在", :forecast=>"(5時51分 現在)晴れ", :max_temp=>nil, :min_temp=>nil, :rain=>nil}]
|
25
|
+
dummy = ["現在の天気: (5時51分 現在)晴れ. 7°C (体感気温 8). 湿度: 89"]
|
26
|
+
WeatherJp::Wrapper.set_weathers(dummy).should == expect
|
15
27
|
end
|
16
28
|
end
|
17
29
|
|
18
30
|
describe ".parse_rss" do
|
19
31
|
it "should parse rss data" do
|
20
|
-
expect = ["今日: 晴のち雨. 最低: 24°C. 最高: 29°C. 降水確率: 80",
|
32
|
+
expect = ["今日: 晴のち雨. 最低: 24°C. 最高: 29°C. 降水確率: 80",
|
33
|
+
"明日: 雨のち晴. 最低: 22°C. 最高: 30°C. 降水確率: 60",
|
34
|
+
"火曜日: 曇時々晴. 最低: 22°C. 最高: 27°C. 降水確率: 30",
|
35
|
+
"水曜日: 曇時々雨. 最低: 20°C. 最高: 25°C. 降水確率: 50",
|
36
|
+
"木曜日: 曇り. 最低: 20°C. 最高: 28°C. 降水確率: 40"
|
37
|
+
]
|
21
38
|
WeatherJp::Wrapper.parse_rss(get_dummy_rss).should == expect
|
22
39
|
end
|
23
40
|
|
41
|
+
it "should parse non-japan data" do
|
42
|
+
expect = ["現在の天気: (5時51分 現在)晴れ. 7°C (体感気温 8). 湿度: 89"]
|
43
|
+
WeatherJp::Wrapper.parse_rss(get_ny_rss).should == expect
|
44
|
+
end
|
45
|
+
|
24
46
|
describe ".remove_html_tag" do
|
25
47
|
it "should remove html tags" do
|
26
48
|
str = %q(<html>a<a href="dummy">b</a><span>c</sapan></html>)
|
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: 1.0.
|
4
|
+
version: 1.0.2
|
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-10-
|
12
|
+
date: 2012-10-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -95,6 +95,7 @@ files:
|
|
95
95
|
- lib/weather_jp/version.rb
|
96
96
|
- spec/day_weather_spec.rb
|
97
97
|
- spec/fixture/RSS.rss
|
98
|
+
- spec/fixture/ny.rss
|
98
99
|
- spec/spec_helper.rb
|
99
100
|
- spec/weather_jp_spec.rb
|
100
101
|
- spec/weather_spec.rb
|
@@ -114,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
114
115
|
version: '0'
|
115
116
|
segments:
|
116
117
|
- 0
|
117
|
-
hash:
|
118
|
+
hash: -2712567142271719011
|
118
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
119
120
|
none: false
|
120
121
|
requirements:
|
@@ -123,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
124
|
version: '0'
|
124
125
|
segments:
|
125
126
|
- 0
|
126
|
-
hash:
|
127
|
+
hash: -2712567142271719011
|
127
128
|
requirements: []
|
128
129
|
rubyforge_project:
|
129
130
|
rubygems_version: 1.8.23
|
@@ -133,6 +134,7 @@ summary: Japan weather info API wrapper.
|
|
133
134
|
test_files:
|
134
135
|
- spec/day_weather_spec.rb
|
135
136
|
- spec/fixture/RSS.rss
|
137
|
+
- spec/fixture/ny.rss
|
136
138
|
- spec/spec_helper.rb
|
137
139
|
- spec/weather_jp_spec.rb
|
138
140
|
- spec/weather_spec.rb
|