weather-report 0.3.6 → 0.3.7
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.
- checksums.yaml +4 -4
- data/bin/weather-report +9 -5
- data/lib/weather-report.rb +9 -0
- data/lib/weather-report/day.rb +1 -0
- data/lib/weather-report/version.rb +1 -1
- data/lib/weather-report/weather.rb +1 -10
- data/test/test_day.rb +6 -0
- data/test/test_weather.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a54cde6c43574f517d352bb0108e4df59e489502
|
4
|
+
data.tar.gz: 9abe9627e9648796999cc617f3a8e1c01562e571
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04357dbeee595b0778420964c5d3103fcb07229489bbb50fa06386e1c12224820f7ad4efd9cf8b8ce5205539a9090a6fe68bb302f50da954a3e2eae474e14ff6
|
7
|
+
data.tar.gz: 35e2f06ec179721583ef66aab3f70e626e3b0947c7de6f73ebc5c1f4d60b128e3159baf591d0bbf1940ad7f82d3f94a07b71b9b4141b022bbcadfd7fc639487f
|
data/bin/weather-report
CHANGED
@@ -14,7 +14,7 @@ opt_parser = OptionParser.new do |opts|
|
|
14
14
|
opts.separator ""
|
15
15
|
opts.separator "Common options:"
|
16
16
|
|
17
|
-
opts.on_tail("-list", "Show city list") do
|
17
|
+
opts.on_tail("-l", "--list", "Show city list") do
|
18
18
|
WeatherReport.cities.each do |city|
|
19
19
|
puts city
|
20
20
|
end
|
@@ -41,9 +41,13 @@ city = opt_parser.parse(ARGV)
|
|
41
41
|
weather = WeatherReport::Weather.new(WeatherReport::Weather.request_cityid(*city))
|
42
42
|
|
43
43
|
[weather.today, weather.tomorrow, weather.day_after_tomorrow].each do |day|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
begin
|
45
|
+
print "#{day.date.year}年#{day.date.month}月#{day.date.day}日の天気 #{day.telop}"
|
46
|
+
print " 最低気温#{day.temperature_min}度" if day.temperature_min
|
47
|
+
print " 最高気温#{day.temperature_max}度" if day.temperature_max
|
48
|
+
puts
|
49
|
+
rescue NoMethodError
|
50
|
+
next
|
51
|
+
end
|
48
52
|
end
|
49
53
|
puts weather.link
|
data/lib/weather-report.rb
CHANGED
@@ -14,4 +14,13 @@ module WeatherReport
|
|
14
14
|
def self.get(city_name)
|
15
15
|
Weather.new(Weather.request_cityid(city_name))
|
16
16
|
end
|
17
|
+
|
18
|
+
# @return [Array] get city list
|
19
|
+
def self.cities
|
20
|
+
proxy = Weather.parse_proxy(ENV["http_proxy"])
|
21
|
+
doc = Nokogiri::XML(open("http://weather.livedoor.com/forecast/rss/primary_area.xml", :proxy_http_basic_authentication => [proxy.server, proxy.user, proxy.pass]))
|
22
|
+
doc.xpath("//city").map{|i|
|
23
|
+
i["title"]
|
24
|
+
}
|
25
|
+
end
|
17
26
|
end
|
data/lib/weather-report/day.rb
CHANGED
@@ -1,14 +1,6 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
3
|
module WeatherReport
|
4
|
-
def self.cities
|
5
|
-
proxy = Weather.parse_proxy(ENV["http_proxy"])
|
6
|
-
doc = Nokogiri::XML(open("http://weather.livedoor.com/forecast/rss/primary_area.xml", :proxy_http_basic_authentication => [proxy.server, proxy.user, proxy.pass]))
|
7
|
-
doc.xpath("//city").map{|i|
|
8
|
-
i["title"]
|
9
|
-
}
|
10
|
-
end
|
11
|
-
|
12
4
|
class Weather
|
13
5
|
attr_reader :today, :tomorrow, :day_after_tomorrow
|
14
6
|
|
@@ -18,13 +10,12 @@ module WeatherReport
|
|
18
10
|
|
19
11
|
# @return [String] the id of given city
|
20
12
|
def self.request_cityid(city_name)
|
13
|
+
raise ArgumentError, "City name must be String." unless city_name.kind_of?(String)
|
21
14
|
proxy = Weather.parse_proxy(ENV["http_proxy"])
|
22
15
|
doc = Nokogiri::XML(open("http://weather.livedoor.com/forecast/rss/primary_area.xml", :proxy_http_basic_authentication => [proxy.server, proxy.user, proxy.pass]))
|
23
16
|
doc.search("//city[@title='#{city_name}']").attr("id").value
|
24
17
|
rescue NoMethodError
|
25
18
|
raise WeatherReportError, "It seems like city #{city_name} does not exist.\nPlease look at http://weather.livedoor.com/forecast/rss/primary_area.xml for city list."
|
26
|
-
rescue => e
|
27
|
-
raise WeatherReportError
|
28
19
|
end
|
29
20
|
|
30
21
|
def self.parse_proxy(proxy)
|
data/test/test_day.rb
CHANGED
@@ -51,4 +51,10 @@ class TestDay < MiniTest::Unit::TestCase
|
|
51
51
|
def test_to_h
|
52
52
|
assert_respond_to @day, :to_h
|
53
53
|
end
|
54
|
+
|
55
|
+
def test_send
|
56
|
+
forecasts = {"forecasts" => [{"dateLabel" => "明日"}]}
|
57
|
+
refute_nil @day.send(:forecast, forecasts, "明日")
|
58
|
+
assert_nil @day.send(:forecast, forecasts, "明後日")
|
59
|
+
end
|
54
60
|
end
|
data/test/test_weather.rb
CHANGED
@@ -47,7 +47,7 @@ class TestWeather < MiniTest::Unit::TestCase
|
|
47
47
|
assert_respond_to Weather, :request_cityid
|
48
48
|
assert_equal "130010", Weather.request_cityid("東京")
|
49
49
|
assert_equal "140010", Weather.request_cityid("横浜")
|
50
|
-
assert_raises(
|
50
|
+
assert_raises(ArgumentError) do
|
51
51
|
Weather.request_cityid(nil)
|
52
52
|
end
|
53
53
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weather-report
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zakuni
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: nokogiri
|
@@ -163,3 +163,4 @@ test_files:
|
|
163
163
|
- test/test_helper.rb
|
164
164
|
- test/test_weather-report.rb
|
165
165
|
- test/test_weather.rb
|
166
|
+
has_rdoc:
|