weather_hacker 0.0.2 → 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 CHANGED
@@ -23,22 +23,27 @@ Or install it yourself as:
23
23
  require "weather_hacker"
24
24
 
25
25
  zipcode = "690-0261"
26
- client = WeatherHacker::Client.new
26
+ weather = WeatherHacker.new(zipcode)
27
27
 
28
- client.get_weather(zipcode)
28
+ weather.on(Date.today)
29
29
  #=> {
30
30
  # "weather" => "晴れ",
31
31
  # "temperature" => { "max" => "18", "min" => "1" }
32
32
  # }
33
33
 
34
- client.get_weather(zipcode, :day => :tomorrow)
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,6 +1,6 @@
1
1
  # encoding: UTF-8
2
2
 
3
- module WeatherHacker
3
+ class WeatherHacker
4
4
  class Client
5
5
  include HTTParty
6
6
 
@@ -1,3 +1,3 @@
1
- module WeatherHacker
2
- VERSION = "0.0.2"
1
+ class WeatherHacker
2
+ VERSION = "0.1.0"
3
3
  end
@@ -3,6 +3,30 @@ require "httparty"
3
3
  require "weather_hacker/version"
4
4
  require "weather_hacker/client"
5
5
 
6
- module WeatherHacker
7
- # Your code goes here...
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
@@ -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
- subject { WeatherHacker }
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
- it do
7
- should be_true
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.2
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: &70309970750560 !ruby/object:Gem::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: *70309970750560
24
+ version_requirements: *70211207058840
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: httparty
27
- requirement: &70309970750140 !ruby/object:Gem::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: *70309970750140
35
+ version_requirements: *70211207058420
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70309970749680 !ruby/object:Gem::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: *70309970749680
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: -1050853293578998898
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: -1050853293578998898
93
+ hash: -2444633236054431010
94
94
  requirements: []
95
95
  rubyforge_project:
96
96
  rubygems_version: 1.8.15