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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa16ff0ec30a13f5f0a926faf7524f184a383721
4
- data.tar.gz: a0180b74e86e87db051b2d754a8a46c379ac703f
3
+ metadata.gz: a54cde6c43574f517d352bb0108e4df59e489502
4
+ data.tar.gz: 9abe9627e9648796999cc617f3a8e1c01562e571
5
5
  SHA512:
6
- metadata.gz: 64cd6ca1ccbd073e13ce7794a0a7094ac18cf6382d0d048161589dbf6e905beeb44ca30279545e2e151a7af929bbb6323e7aba8d449a085eedac0a4caec702d7
7
- data.tar.gz: 5da091b6efa977c7879f9ad38c1409ecc91979c349a81d9c3394ff9d873b4bcc7cd4e883ab661e343e138f318ad5aa6bc5254558bdadb0617965686a5c6ff797
6
+ metadata.gz: 04357dbeee595b0778420964c5d3103fcb07229489bbb50fa06386e1c12224820f7ad4efd9cf8b8ce5205539a9090a6fe68bb302f50da954a3e2eae474e14ff6
7
+ data.tar.gz: 35e2f06ec179721583ef66aab3f70e626e3b0947c7de6f73ebc5c1f4d60b128e3159baf591d0bbf1940ad7f82d3f94a07b71b9b4141b022bbcadfd7fc639487f
@@ -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
- print "#{day.date.year}年#{day.date.month}月#{day.date.day}日の天気 #{day.telop}"
45
- print " 最低気温#{day.temperature_min}度" if day.temperature_min
46
- print " 最高気温#{day.temperature_max}度" if day.temperature_max
47
- puts
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
@@ -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
@@ -64,6 +64,7 @@ module WeatherReport
64
64
 
65
65
  def forecast(forecasts, dateLabel)
66
66
  forecasts["forecasts"].each {|elem| return elem if elem["dateLabel"] == dateLabel}
67
+ return nil
67
68
  end
68
69
  end
69
70
  end
@@ -1,3 +1,3 @@
1
1
  module WeatherReport
2
- VERSION = "0.3.6"
2
+ VERSION = "0.3.7"
3
3
  end
@@ -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)
@@ -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
@@ -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(WeatherReportError) do
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.6
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-08-11 00:00:00.000000000 Z
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: