weather-report 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 760746840f014f0120e729148e4f61516212875f
4
- data.tar.gz: 1ceb9967c055c7b6a89fa90de5168eeef1f0ab91
3
+ metadata.gz: b9a69683ca8b735ec9e07e7d122d9fd211c0d6f4
4
+ data.tar.gz: 48b6373985b7cbd42f832a039ac8433c1b3765c7
5
5
  SHA512:
6
- metadata.gz: 0ae3d76979a77a7519ca8153b2a2706af9a7e65686bf1bb282801f1c4f6de8c9fbea9483f5fca14456990afa6f704166a9415fc3c900104fe4012c7a66e10d31
7
- data.tar.gz: 52938d64da714d90db1e8dcf7aa52f360bff6e24c3446cf2703466cc7dac0a5f255e778e86c9cbe990942aed7f9a17a0703dbfa99d98420816950e60e9cc4c01
6
+ metadata.gz: 718e0f6b78773654966babdce38df8d48b53153456ab38d80b9c0cb03e4c3e68eb21dbe96d6c9035ff900e93c7bcb8879cb4e4139963712414884fae3b5d2aa6
7
+ data.tar.gz: bd80b590a03d97349c2528b701ee10b503f594ae3434ff47c508c59ce857cbdea5354dfe02db496399766f8dc972043707629f4d166418be9f1d6eb426cf61f6
data/README.md CHANGED
@@ -23,7 +23,7 @@ require 'weather-report'
23
23
 
24
24
  id = WeatherReport::Weather.request_cityid("東京")
25
25
  weather = WeatherReport::Weather.new(id)
26
- weather.tomorrow.date # => Date: 2013-05-04 ((2456417j,0s,0n),+0s,2299161j)>
26
+ weather.tomorrow.date # => <Date: 2013-05-04 ((2456417j,0s,0n),+0s,2299161j)>
27
27
  weather.tomorrow.telop # => "雨"
28
28
  weather.tomorrow.temperature_min # => 12
29
29
  ```
data/bin/weather-report CHANGED
@@ -1,3 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'weather-report'
4
+
5
+ weather = WeatherReport::Weather.new(WeatherReport::Weather.request_cityid(ARGV[0]))
6
+ puts weather.to_h
@@ -9,4 +9,8 @@ require 'weather-report/version'
9
9
 
10
10
  module WeatherReport
11
11
  class WeatherReportError < StandardError; end
12
+
13
+ def self.get(city)
14
+ Weather.new(Weather.request_cityid(city))
15
+ end
12
16
  end
@@ -35,6 +35,15 @@ module WeatherReport
35
35
  max ? max["celsius"].to_i : nil
36
36
  end
37
37
 
38
+ def to_h
39
+ {
40
+ "date" => date.to_s,
41
+ "telop" => telop,
42
+ "temperature_min" => temperature_min,
43
+ "temperature_max" => temperature_max
44
+ }
45
+ end
46
+
38
47
  private
39
48
 
40
49
  def forecast(forecasts, dateLabel)
@@ -1,3 +1,3 @@
1
1
  module WeatherReport
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -12,7 +12,7 @@ module WeatherReport
12
12
  def self.request_cityid(city)
13
13
  doc = Nokogiri::XML(open("http://weather.livedoor.com/forecast/rss/primary_area.xml"))
14
14
  doc.search("//city[@title='#{city}']").attr("id").value
15
- rescue
15
+ rescue => e
16
16
  raise WeatherReportError
17
17
  end
18
18
 
@@ -31,6 +31,14 @@ module WeatherReport
31
31
  @day_after_tomorrow ||= Day.new(forecasts, "明後日")
32
32
  end
33
33
 
34
+ def to_h
35
+ {
36
+ "today" => today.to_h,
37
+ "tomorrow" => tomorrow.to_h,
38
+ "day_after_tomorrow" => day_after_tomorrow.to_h
39
+ }
40
+ end
41
+
34
42
  private
35
43
 
36
44
  def forecasts
@@ -39,7 +47,7 @@ module WeatherReport
39
47
 
40
48
  def read
41
49
  @response ||= JSON.parse(@uri.read)
42
- rescue e
50
+ rescue => e
43
51
  raise WeatherReportError
44
52
  end
45
53
  end
@@ -3,5 +3,9 @@
3
3
  require 'test_helper'
4
4
 
5
5
  class TestWeatherReport < MiniTest::Unit::TestCase
6
-
6
+
7
+ def test_get
8
+ assert_respond_to WeatherReport, :get
9
+ assert_instance_of WeatherReport::Weather, WeatherReport.get("横浜")
10
+ end
7
11
  end
@@ -34,4 +34,9 @@ class TestDay < MiniTest::Unit::TestCase
34
34
  assert_respond_to @day, :temperature_max
35
35
  assert_instance_of Fixnum, @day.temperature_max
36
36
  end
37
+
38
+ def test_to_h
39
+ assert_respond_to @day, :to_h
40
+ puts @day.to_h
41
+ end
37
42
  end
@@ -46,4 +46,9 @@ class TestWeather < MiniTest::Unit::TestCase
46
46
  Weather.request_cityid(nil)
47
47
  end
48
48
  end
49
+
50
+ def test_to_h
51
+ assert_respond_to @weather, :to_h
52
+ puts @weather.to_h
53
+ end
49
54
  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.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - zakuni
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-05-03 00:00:00.000000000 Z
11
+ date: 2013-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri