weather_jp 0.0.8 → 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.
- data/README.md +22 -1
- data/lib/weather_jp/version.rb +1 -1
- data/lib/weather_jp.rb +14 -0
- data/spec/weather_jp_spec.rb +27 -0
- data/spec/weather_spec.rb +1 -1
- metadata +6 -4
data/README.md
CHANGED
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
## About
|
|
4
4
|
|
|
5
|
+
Japan weather info API wrapper.
|
|
6
|
+
|
|
5
7
|
Fetch Japan weather info as Ruby object easily.
|
|
6
8
|
|
|
7
9
|
http://taiki45.github.com/weather_jp
|
|
@@ -26,6 +28,7 @@ Or install it yourself as:
|
|
|
26
28
|
|
|
27
29
|
```ruby
|
|
28
30
|
# creat weather object in differrnt ways
|
|
31
|
+
tokyo = WeatherJp.get :today
|
|
29
32
|
tokyo = WeatherJp::Weather.new :tokyo
|
|
30
33
|
minato = WeatherJp::Weather.new("東京都港区")
|
|
31
34
|
|
|
@@ -38,12 +41,16 @@ minato.get_weather(4) #=> <#DayWeather object>
|
|
|
38
41
|
minato.today.forecast #=> can be "晴れ"
|
|
39
42
|
tokyo.get_weather(:tomorrow).rain
|
|
40
43
|
minato.day_after_tomorrow.to_s
|
|
44
|
+
Weather.get(:tokyo, :today).forecast
|
|
41
45
|
|
|
42
46
|
# use Weather object
|
|
43
47
|
tokyo.each do |w|
|
|
44
48
|
puts w.city_name
|
|
49
|
+
puts w.day
|
|
45
50
|
puts w.forecast
|
|
46
51
|
puts w.max_temp
|
|
52
|
+
puts w.min_temp
|
|
53
|
+
puts w.rain
|
|
47
54
|
w.each_pair {|k,v| puts k, v }
|
|
48
55
|
end
|
|
49
56
|
|
|
@@ -53,6 +60,20 @@ minato.map {|w| [w.day, w.forecast] }
|
|
|
53
60
|
tokyo.to_a
|
|
54
61
|
minato.each {|w| p w.to_hash }
|
|
55
62
|
|
|
63
|
+
# you can cutomize DayWeather#to_s method
|
|
64
|
+
Weather.get(:tokyo).today.to_s #=> "東京 東京都の天気は晴れ....etc"
|
|
65
|
+
|
|
66
|
+
Weather.customize_to_s do
|
|
67
|
+
word = "#{day}の#{city_name}は#{forecast} "
|
|
68
|
+
word << "最高気温は#{max_temp} " if max_temp
|
|
69
|
+
word << "最低気温は#{min_temp} " if min_temp
|
|
70
|
+
word << "降水確率は#{rain}%" if rain
|
|
71
|
+
word << "でし"
|
|
72
|
+
word
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
Weather.get(:tokyo).today.to_s #=> "本日の東京 東京都は晴れ...."
|
|
76
|
+
|
|
56
77
|
```
|
|
57
78
|
|
|
58
79
|
## Requires
|
|
@@ -61,7 +82,7 @@ Ruby >= 1.9.2
|
|
|
61
82
|
|
|
62
83
|
## Documents
|
|
63
84
|
|
|
64
|
-
http://rubydoc.info/gems/weather_jp/
|
|
85
|
+
http://rubydoc.info/gems/weather_jp/
|
|
65
86
|
|
|
66
87
|
## Contributing
|
|
67
88
|
|
data/lib/weather_jp/version.rb
CHANGED
data/lib/weather_jp.rb
CHANGED
|
@@ -7,6 +7,20 @@ require 'rss'
|
|
|
7
7
|
require 'nokogiri'
|
|
8
8
|
|
|
9
9
|
module WeatherJp
|
|
10
|
+
def self.get(city_name, option = nil)
|
|
11
|
+
if option
|
|
12
|
+
Weather.new(city_name).get_weather(option)
|
|
13
|
+
else
|
|
14
|
+
Weather.new(city_name)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.customize_to_s(&code)
|
|
19
|
+
Weather::DayWeather.class_eval do
|
|
20
|
+
define_method(:to_s, &code)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
10
24
|
class Weather
|
|
11
25
|
include Enumerable
|
|
12
26
|
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
require 'spec_helper'
|
|
3
|
+
|
|
4
|
+
describe "WeatherJp" do
|
|
5
|
+
before(:all) do
|
|
6
|
+
@weather = WeatherJp.get :tokyo
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe ".get" do
|
|
10
|
+
it "should return Weather instance" do
|
|
11
|
+
@weather.class.should == WeatherJp::Weather
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "should accept option and return DayWeather object" do
|
|
15
|
+
WeatherJp.get(:tokyo, :today).class.
|
|
16
|
+
should == WeatherJp::Weather::DayWeather
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe ".customize_to_s" do
|
|
21
|
+
it "should customize DayWeather#to_s" do
|
|
22
|
+
WeatherJp.customize_to_s { 'success' }
|
|
23
|
+
WeatherJp.get(:tokyo, :today).to_s.should == 'success'
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
data/spec/weather_spec.rb
CHANGED
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: 0.0
|
|
4
|
+
version: 0.1.0
|
|
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-08-
|
|
12
|
+
date: 2012-08-04 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: nokogiri
|
|
@@ -93,6 +93,7 @@ files:
|
|
|
93
93
|
- lib/weather_jp/version.rb
|
|
94
94
|
- spec/day_weather_spec.rb
|
|
95
95
|
- spec/spec_helper.rb
|
|
96
|
+
- spec/weather_jp_spec.rb
|
|
96
97
|
- spec/weather_spec.rb
|
|
97
98
|
- weather_jp.gemspec
|
|
98
99
|
homepage: http://taiki45.github.com/weather_jp
|
|
@@ -109,7 +110,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
109
110
|
version: '0'
|
|
110
111
|
segments:
|
|
111
112
|
- 0
|
|
112
|
-
hash:
|
|
113
|
+
hash: 21516764662165991
|
|
113
114
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
114
115
|
none: false
|
|
115
116
|
requirements:
|
|
@@ -118,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
118
119
|
version: '0'
|
|
119
120
|
segments:
|
|
120
121
|
- 0
|
|
121
|
-
hash:
|
|
122
|
+
hash: 21516764662165991
|
|
122
123
|
requirements: []
|
|
123
124
|
rubyforge_project:
|
|
124
125
|
rubygems_version: 1.8.23
|
|
@@ -128,4 +129,5 @@ summary: Japan weather info API wrapper.
|
|
|
128
129
|
test_files:
|
|
129
130
|
- spec/day_weather_spec.rb
|
|
130
131
|
- spec/spec_helper.rb
|
|
132
|
+
- spec/weather_jp_spec.rb
|
|
131
133
|
- spec/weather_spec.rb
|