weather_hacker 0.0.2 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +10 -5
- data/lib/weather_hacker/client.rb +1 -1
- data/lib/weather_hacker/version.rb +2 -2
- data/lib/weather_hacker.rb +26 -2
- data/spec/weather_hacker_spec.rb +45 -3
- metadata +9 -9
data/README.md
CHANGED
@@ -23,22 +23,27 @@ Or install it yourself as:
|
|
23
23
|
require "weather_hacker"
|
24
24
|
|
25
25
|
zipcode = "690-0261"
|
26
|
-
|
26
|
+
weather = WeatherHacker.new(zipcode)
|
27
27
|
|
28
|
-
|
28
|
+
weather.on(Date.today)
|
29
29
|
#=> {
|
30
30
|
# "weather" => "晴れ",
|
31
31
|
# "temperature" => { "max" => "18", "min" => "1" }
|
32
32
|
# }
|
33
33
|
|
34
|
-
|
34
|
+
weather.today
|
35
|
+
#=> {
|
36
|
+
# "weather" => "晴れ",
|
37
|
+
# "temperature" => { "max" => "18", "min" => "1" }
|
38
|
+
# }
|
39
|
+
|
40
|
+
weather.tomorrow
|
35
41
|
#=> {
|
36
42
|
# "weather" => "晴時々曇",
|
37
43
|
# "temperature" => { "max" => 21, "min" => 9 }
|
38
44
|
# }
|
39
45
|
|
40
|
-
|
41
|
-
client.get_weather(zipcode, :day => :dayaftertomorrow)
|
46
|
+
weather.day_after_tomorrow
|
42
47
|
#=> {
|
43
48
|
# "weather" => "晴時々曇",
|
44
49
|
# "temperature" => { "max" => nil, "min" => nil }
|
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = "0.0
|
1
|
+
class WeatherHacker
|
2
|
+
VERSION = "0.1.0"
|
3
3
|
end
|
data/lib/weather_hacker.rb
CHANGED
@@ -3,6 +3,30 @@ require "httparty"
|
|
3
3
|
require "weather_hacker/version"
|
4
4
|
require "weather_hacker/client"
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
class WeatherHacker
|
7
|
+
def initialize(zipcode)
|
8
|
+
@zipcode = zipcode
|
9
|
+
@client = Client.new
|
10
|
+
end
|
11
|
+
|
12
|
+
# define these methods
|
13
|
+
# * WeatherHacker#today(zipcode)
|
14
|
+
# * WeatherHacker#tomorrow(zipcode)
|
15
|
+
# * WeatherHacker#dayaftertomorrow(zipcode)
|
16
|
+
[:today, :tomorrow, :day_after_tomorrow].each do |day|
|
17
|
+
define_method(day) do
|
18
|
+
@client.get_weather(@zipcode, :day => day.to_s.tr("_", ""))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# return weather data on the received date
|
23
|
+
# if the date is not supported, return nil
|
24
|
+
def on(date)
|
25
|
+
now = Date.today
|
26
|
+
{
|
27
|
+
now => today,
|
28
|
+
now + 1 => tomorrow,
|
29
|
+
now + 2 => day_after_tomorrow,
|
30
|
+
}[date]
|
31
|
+
end
|
8
32
|
end
|
data/spec/weather_hacker_spec.rb
CHANGED
@@ -1,9 +1,51 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require "date"
|
1
4
|
require "spec_helper"
|
2
5
|
|
3
6
|
describe "WeatherHacker" do
|
4
|
-
|
7
|
+
before do
|
8
|
+
@weather = WeatherHacker.new("690-0261")
|
9
|
+
end
|
10
|
+
|
11
|
+
shared_examples_for "WeatherResult" do
|
12
|
+
it "should have weather data" do
|
13
|
+
should be_kind_of Hash
|
14
|
+
should have_key "weather"
|
15
|
+
should have_key "temperature"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#initialize" do
|
20
|
+
it "should have client attribute" do
|
21
|
+
@weather.instance_variable_get(:@client).should_not be_nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#today" do
|
26
|
+
subject { @weather.today }
|
27
|
+
it_should_behave_like "WeatherResult"
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#tomorrow" do
|
31
|
+
subject { @weather.today }
|
32
|
+
it_should_behave_like "WeatherResult"
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#day_after_tomorrow" do
|
36
|
+
subject { @weather.today }
|
37
|
+
it_should_behave_like "WeatherResult"
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "#on" do
|
41
|
+
context "when passed date in unavailable range" do
|
42
|
+
subject { @weather.on(Date.new(2000, 1, 1)) }
|
43
|
+
it { should be_nil }
|
44
|
+
end
|
5
45
|
|
6
|
-
|
7
|
-
|
46
|
+
context "when passed date in available range" do
|
47
|
+
subject { @weather.on(Date.today) }
|
48
|
+
it_should_behave_like "WeatherResult"
|
49
|
+
end
|
8
50
|
end
|
9
51
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weather_hacker
|
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:
|
@@ -13,7 +13,7 @@ date: 2012-04-08 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70211207058840 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 0.9.2
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70211207058840
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: httparty
|
27
|
-
requirement: &
|
27
|
+
requirement: &70211207058420 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70211207058420
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70211207057960 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70211207057960
|
47
47
|
description: Library for Livedoor Weather Web Service
|
48
48
|
email:
|
49
49
|
- r7kamura@gmail.com
|
@@ -81,7 +81,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
81
|
version: '0'
|
82
82
|
segments:
|
83
83
|
- 0
|
84
|
-
hash: -
|
84
|
+
hash: -2444633236054431010
|
85
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
86
|
none: false
|
87
87
|
requirements:
|
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
90
|
version: '0'
|
91
91
|
segments:
|
92
92
|
- 0
|
93
|
-
hash: -
|
93
|
+
hash: -2444633236054431010
|
94
94
|
requirements: []
|
95
95
|
rubyforge_project:
|
96
96
|
rubygems_version: 1.8.15
|