weather-report 0.0.1 → 0.1.0

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: af1d8192f60c896b77e6ce11143ab06ed934ff7f
4
- data.tar.gz: e1d2070cb70c0ce54e8b6f521ef023cd01b66a69
3
+ metadata.gz: e40fcae0d080a18d08175ed911738a01caaff265
4
+ data.tar.gz: cec9d9bd30cdf41f4533cd4a327097372cacbf47
5
5
  SHA512:
6
- metadata.gz: 4197fa2fdb3e78d748d4423c940e2910c7b328be3d195dc410e4e420ff6b13dc9f8480b2282b5a292d83b67fe1d36eeab45768d246eb011f961be347fd5e030a
7
- data.tar.gz: ced5d01c569fa21cc33ea9383326b075a906c941fadc758c205a3fe531db5200316d46e69f21ebd43b63dfcd590b5c94c5c514199db9adb8b74c1e5ef06b90d9
6
+ metadata.gz: 1931597a94a6bfba4666ea5703397826a8f9b244944fa88a2641a971a0ac6c39ccb45339025c0a794029c4b7833cffc434fe3dc3165f0057ed55ddfe8577cf67
7
+ data.tar.gz: 5e06046a028d6294de4e0cd680fd05953045d3b7d5a921adeb2d84d337aaba10c35613f861aa094b968b2932344d9c6a77cb75184d9373669654419fc1ae5b57
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Weather Report
2
2
 
3
- A Ruby library and CLI to access Livedoor Weather Web Service(http://weather.livedoor.com/weather_hacks/webservice).
3
+ A Ruby library and CLI to get Japanese Weather via Livedoor Weather Web Service(http://weather.livedoor.com/weather_hacks/webservice).
4
4
 
5
5
  ## Installation
6
6
 
@@ -23,6 +23,9 @@ 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)>
27
+ weather.tomorrow.telop # => "雨"
28
+ weather.tomorrow.temperature_min # => 12
26
29
  ```
27
30
 
28
31
  ## Contributing
@@ -0,0 +1,38 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module WeatherReport
4
+ class Day
5
+ attr_reader :date, :telop, :temperature_min, :temperature_max
6
+
7
+ def initialize(forecasts, dateLabel)
8
+ @forecast = forecast(forecasts, dateLabel)
9
+ end
10
+
11
+ def date
12
+ year, month, day = @forecast["date"].split('-')
13
+ @date ||= Date.new(year.to_i, month.to_i, day.to_i)
14
+ end
15
+
16
+ def telop
17
+ @telop ||= @forecast["telop"]
18
+ end
19
+
20
+ def temperature_min
21
+ min = @forecast["temperature"]["min"]
22
+ @temperature ||=
23
+ min ? min["celsius"].to_i : nil
24
+ end
25
+
26
+ def temperature_max
27
+ max = @forecast["temperature"]["max"]
28
+ @temperature_max ||=
29
+ max ? max["celsius"].to_i : nil
30
+ end
31
+
32
+ private
33
+
34
+ def forecast(forecasts, dateLabel)
35
+ forecasts["forecasts"].each {|elem| return elem if elem["dateLabel"] == dateLabel}
36
+ end
37
+ end
38
+ end
@@ -1,3 +1,3 @@
1
1
  module WeatherReport
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,42 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ module WeatherReport
4
+ class Weather
5
+ attr_reader :today, :tomorrow, :day_after_tomorrow
6
+
7
+ def initialize(city_id)
8
+ @uri = URI.parse("http://weather.livedoor.com/forecast/webservice/json/v1?city=#{city_id}")
9
+ end
10
+
11
+ def self.request_cityid(city)
12
+ doc = Nokogiri::XML(open("http://weather.livedoor.com/forecast/rss/primary_area.xml"))
13
+ doc.search("//city[@title='#{city}']").attr("id").value
14
+ rescue
15
+ raise WeatherReportError
16
+ end
17
+
18
+ def today
19
+ @today ||= Day.new(forecasts, "今日")
20
+ end
21
+
22
+ def tomorrow
23
+ @tomorrow ||= Day.new(forecasts, "明日")
24
+ end
25
+
26
+ def day_after_tomorrow
27
+ @day_after_tomorrow ||= Day.new(forecasts, "明後日")
28
+ end
29
+
30
+ private
31
+
32
+ def forecasts
33
+ @forecasts ||= read
34
+ end
35
+
36
+ def read
37
+ @response ||= JSON.parse(@uri.read)
38
+ rescue e
39
+ raise WeatherReportError
40
+ end
41
+ end
42
+ end
@@ -1,52 +1,12 @@
1
1
  # -*- coding: utf-8 -*-
2
+ require 'date'
2
3
  require 'json'
3
4
  require 'open-uri'
4
5
  require 'nokogiri'
5
- require "weather-report/version"
6
+ require 'weather-report/weather'
7
+ require 'weather-report/day'
8
+ require 'weather-report/version'
6
9
 
7
10
  module WeatherReport
8
11
  class WeatherReportError < StandardError; end
9
-
10
- class Weather
11
- attr_reader :today, :tomorrow, :day_after_tomorrow
12
-
13
- def initialize(city_id)
14
- @uri = URI.parse("http://weather.livedoor.com/forecast/webservice/json/v1?city=#{city_id}")
15
- end
16
-
17
- def self.request_cityid(city)
18
- doc = Nokogiri::XML(open("http://weather.livedoor.com/forecast/rss/primary_area.xml"))
19
- doc.search("//city[@title='#{city}']").attr("id").value
20
- rescue
21
- raise WeatherReportError
22
- end
23
-
24
- def today
25
- @today ||= forecast("今日")
26
- end
27
-
28
- def tomorrow
29
- @tomorrow ||= forecast("明日")
30
- end
31
-
32
- def day_after_tomorrow
33
- @day_after_tomorrow ||= forecast("明後日")
34
- end
35
-
36
- private
37
-
38
- def forecast(dateLabel)
39
- forecasts.each {|elem| return elem if elem["dateLabel"] == dateLabel}
40
- end
41
-
42
- def forecasts
43
- @forecasts ||= read["forecasts"]
44
- end
45
-
46
- def read
47
- @response ||= JSON.parse(@uri.read)
48
- rescue
49
- raise WeatherReportError
50
- end
51
- end
52
12
  end
@@ -3,53 +3,5 @@
3
3
  require 'test_helper'
4
4
 
5
5
  class TestWeatherReport < MiniTest::Unit::TestCase
6
- include WeatherReport
7
6
 
8
- def setup
9
- @id = Weather.request_cityid("東京")
10
- @weather = Weather.new(@id)
11
- end
12
-
13
- def test_initialize
14
- assert_raises ArgumentError do
15
- Weather.new
16
- end
17
- assert_instance_of Weather, Weather.new(@id)
18
- end
19
-
20
- def test_today
21
- assert_respond_to @weather, :today
22
-
23
- today = @weather.today
24
- assert_includes(today, "date")
25
- assert_includes(today, "telop")
26
- assert_includes(today, "temperature")
27
- end
28
-
29
- def test_tomorrow
30
- assert_respond_to @weather, :tomorrow
31
-
32
- tomorrow = @weather.tomorrow
33
- assert_includes(tomorrow, "date")
34
- assert_includes(tomorrow, "telop")
35
- assert_includes(tomorrow, "temperature")
36
- end
37
-
38
- def test_day_after_tomorrow
39
- assert_respond_to @weather, :day_after_tomorrow
40
-
41
- day_after_tomorrow = @weather.day_after_tomorrow
42
- assert_includes(day_after_tomorrow, "date")
43
- assert_includes(day_after_tomorrow, "telop")
44
- assert_includes(day_after_tomorrow, "temperature")
45
- end
46
-
47
- def test_request_cityid
48
- assert_respond_to Weather, :request_cityid
49
- assert_equal "130010", Weather.request_cityid("東京")
50
- assert_equal "140010", Weather.request_cityid("横浜")
51
- assert_raises(WeatherReportError) do
52
- Weather.request_cityid(nil)
53
- end
54
- end
55
7
  end
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ require 'test_helper'
4
+
5
+ class TestDay < MiniTest::Unit::TestCase
6
+ include WeatherReport
7
+
8
+ def setup
9
+ city_id = Weather.request_cityid("東京")
10
+ uri = URI.parse("http://weather.livedoor.com/forecast/webservice/json/v1?city=#{city_id}")
11
+ @forecasts = JSON.parse(uri.read)
12
+ @day = Day.new(@forecasts, "明日")
13
+ end
14
+
15
+ def test_initialize
16
+ assert_instance_of Day, Day.new(@forecasts, "明日")
17
+ end
18
+
19
+ def test_date
20
+ assert_respond_to @day, :date
21
+ assert_instance_of Date, @day.date
22
+ end
23
+
24
+ def test_telop
25
+ assert_respond_to @day, :telop
26
+ end
27
+
28
+ def test_temperature_min
29
+ assert_respond_to @day, :temperature_min
30
+ assert_instance_of Fixnum, @day.temperature_min
31
+ end
32
+
33
+ def test_temperature_max
34
+ assert_respond_to @day, :temperature_max
35
+ assert_instance_of Fixnum, @day.temperature_max
36
+ end
37
+ end
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- coding: utf-8 -*-
3
+ require 'test_helper'
4
+
5
+ class TestWeather < MiniTest::Unit::TestCase
6
+ include WeatherReport
7
+
8
+ def setup
9
+ @id = Weather.request_cityid("東京")
10
+ @weather = Weather.new(@id)
11
+ end
12
+
13
+ def test_initialize
14
+ assert_raises ArgumentError do
15
+ Weather.new
16
+ end
17
+ assert_instance_of Weather, Weather.new(@id)
18
+ end
19
+
20
+ def test_today
21
+ assert_respond_to @weather, :today
22
+
23
+ today = @weather.today
24
+ assert_instance_of Day, today
25
+ end
26
+
27
+ def test_tomorrow
28
+ assert_respond_to @weather, :tomorrow
29
+
30
+ tomorrow = @weather.tomorrow
31
+ assert_instance_of Day, tomorrow
32
+ end
33
+
34
+ def test_day_after_tomorrow
35
+ assert_respond_to @weather, :day_after_tomorrow
36
+
37
+ day_after_tomorrow = @weather.day_after_tomorrow
38
+ assert_instance_of Day, day_after_tomorrow
39
+ end
40
+
41
+ def test_request_cityid
42
+ assert_respond_to Weather, :request_cityid
43
+ assert_equal "130010", Weather.request_cityid("東京")
44
+ assert_equal "140010", Weather.request_cityid("横浜")
45
+ assert_raises(WeatherReportError) do
46
+ Weather.request_cityid(nil)
47
+ end
48
+ end
49
+ end
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = WeatherReport::VERSION
9
9
  spec.authors = ["zakuni"]
10
10
  spec.email = ["kunio038@gmail.com"]
11
- spec.description = %q{A Ruby library and CLI to access Livedoor Weather Web Service(http://weather.livedoor.com/weather_hacks/webservice).}
11
+ spec.description = %q{A Ruby library and CLI to get Japanese Weather via Livedoor Weather Web Service(http://weather.livedoor.com/weather_hacks/webservice).}
12
12
  spec.summary = %q{A Ruby client of Livedoor Weather Web Service.}
13
13
  spec.homepage = "https://github.com/zakuni/weather-report"
14
14
  spec.license = "MIT"
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.0.1
4
+ version: 0.1.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-01 00:00:00.000000000 Z
11
+ date: 2013-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -108,7 +108,8 @@ dependencies:
108
108
  - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
- description: A Ruby library and CLI to access Livedoor Weather Web Service(http://weather.livedoor.com/weather_hacks/webservice).
111
+ description: A Ruby library and CLI to get Japanese Weather via Livedoor Weather Web
112
+ Service(http://weather.livedoor.com/weather_hacks/webservice).
112
113
  email:
113
114
  - kunio038@gmail.com
114
115
  executables:
@@ -124,9 +125,13 @@ files:
124
125
  - Rakefile
125
126
  - bin/weather-report
126
127
  - lib/weather-report.rb
128
+ - lib/weather-report/day.rb
127
129
  - lib/weather-report/version.rb
130
+ - lib/weather-report/weather.rb
128
131
  - test/test_helper.rb
129
132
  - test/test_weather-report.rb
133
+ - test/weather-report/test_day.rb
134
+ - test/weather-report/test_weather.rb
130
135
  - weather-report.gemspec
131
136
  homepage: https://github.com/zakuni/weather-report
132
137
  licenses:
@@ -155,4 +160,6 @@ summary: A Ruby client of Livedoor Weather Web Service.
155
160
  test_files:
156
161
  - test/test_helper.rb
157
162
  - test/test_weather-report.rb
163
+ - test/weather-report/test_day.rb
164
+ - test/weather-report/test_weather.rb
158
165
  has_rdoc: