weather_hacker 0.1.0 → 0.1.1

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
@@ -19,36 +19,47 @@ Or install it yourself as:
19
19
  $ gem install weather_hacker
20
20
 
21
21
  ## Usage
22
- ~~~
22
+ Here's an example script to watch the weather forecast:
23
+
24
+ ```ruby
25
+ # forecast.rb
23
26
  require "weather_hacker"
27
+ require "yaml"
28
+ require "date"
24
29
 
25
30
  zipcode = "690-0261"
26
31
  weather = WeatherHacker.new(zipcode)
27
32
 
28
- weather.on(Date.today)
29
- #=> {
30
- # "weather" => "晴れ",
31
- # "temperature" => { "max" => "18", "min" => "1" }
32
- # }
33
-
34
- weather.today
35
- #=> {
36
- # "weather" => "晴れ",
37
- # "temperature" => { "max" => "18", "min" => "1" }
38
- # }
39
-
40
- weather.tomorrow
41
- #=> {
42
- # "weather" => "晴時々曇",
43
- # "temperature" => { "max" => 21, "min" => 9 }
44
- # }
45
-
46
- weather.day_after_tomorrow
47
- #=> {
48
- # "weather" => "晴時々曇",
49
- # "temperature" => { "max" => nil, "min" => nil }
50
- # }
51
- ~~~
33
+ y weather.on(Date.today)
34
+ y weather.today
35
+ y weather.tomorrow
36
+ y weather.day_after_tomorrow
37
+ ```
38
+
39
+ ```
40
+ $ gem install weather_hacker
41
+ $ ruby forecast.rb
42
+ ---
43
+ weather: 晴れ
44
+ temperature:
45
+ max: '18'
46
+ min: '1'
47
+ ---
48
+ weather: 晴れ
49
+ temperature:
50
+ max: '18'
51
+ min: '1'
52
+ ---
53
+ weather: 晴時々曇
54
+ temperature:
55
+ max: '18'
56
+ min: '2'
57
+ ---
58
+ weather: 曇り
59
+ temperature:
60
+ max: '21'
61
+ min: '9'
62
+ ```
52
63
 
53
64
  ## Contributing
54
65
 
@@ -91,8 +91,8 @@ class WeatherHacker
91
91
 
92
92
  # parse area table hash of response from Weather API
93
93
  def parse_area_table(hash)
94
- @pref_by_city = {}
95
- @id_by_city = {}
94
+ @pref_by_city ||= {}
95
+ @id_by_city ||= {}
96
96
 
97
97
  hash["rss"]["channel"]["source"]["area"].each do |area|
98
98
  prefs = [area["pref"]].flatten
@@ -1,3 +1,3 @@
1
1
  class WeatherHacker
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -10,9 +10,9 @@ class WeatherHacker
10
10
  end
11
11
 
12
12
  # define these methods
13
- # * WeatherHacker#today(zipcode)
14
- # * WeatherHacker#tomorrow(zipcode)
15
- # * WeatherHacker#dayaftertomorrow(zipcode)
13
+ # * WeatherHacker#today
14
+ # * WeatherHacker#tomorrow
15
+ # * WeatherHacker#day_after_tomorrow
16
16
  [:today, :tomorrow, :day_after_tomorrow].each do |day|
17
17
  define_method(day) do
18
18
  @client.get_weather(@zipcode, :day => day.to_s.tr("_", ""))
data/spec/spec_helper.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  $LOAD_PATH.unshift File.expand_path("../", __FILE__)
2
2
  $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
3
3
 
4
+ require "simplecov"
4
5
  require "weather_hacker"
@@ -27,16 +27,39 @@ describe "WeatherHacker::Client" do
27
27
  end
28
28
  end
29
29
 
30
- describe "#update_area_table" do
31
- it "has not table before call" do
30
+ shared_examples_for "having area table" do
31
+ it "has area table" do
32
+ @client.send(:id_by_city).keys.size.should_not == 0
33
+ @client.send(:pref_by_city).keys.size.should_not == 0
34
+ end
35
+ end
36
+
37
+ shared_examples_for "not having area table" do
38
+ it "has not area table" do
32
39
  @client.instance_variable_get(:@id_by_city).should be_nil
33
40
  @client.instance_variable_get(:@pref_by_city).should be_nil
34
41
  end
42
+ end
43
+
44
+ describe "#id_by_city" do
45
+ context "before call" do
46
+ it_behaves_like "not having area table"
47
+ end
35
48
 
36
- it "has area table after call" do
37
- @client.send(:update_area_table)
38
- @client.send(:id_by_city).keys.size.should_not == 0
39
- @client.send(:pref_by_city).keys.size.should_not == 0
49
+ context "after call" do
50
+ before { @client.send(:id_by_city) }
51
+ it_behaves_like "having area table"
52
+ end
53
+ end
54
+
55
+ describe "#pref_by_city" do
56
+ context "before call" do
57
+ it_behaves_like "not having area table"
58
+ end
59
+
60
+ context "after call" do
61
+ before { @client.send(:pref_by_city) }
62
+ it_behaves_like "having area table"
40
63
  end
41
64
  end
42
65
 
@@ -46,4 +69,29 @@ describe "WeatherHacker::Client" do
46
69
  city_id.should be_kind_of Integer
47
70
  end
48
71
  end
72
+
73
+ describe "#id_by_pref" do
74
+ it "is cached in instance variable" do
75
+ @client.instance_variable_get(:@id_by_pref).should be_nil
76
+ @client.send(:id_by_pref)
77
+ @client.instance_variable_get(:@id_by_pref).should be_kind_of Hash
78
+
79
+ @client.should_not_receive(:pref_by_city)
80
+ @client.send(:id_by_pref)
81
+ end
82
+
83
+ it "return table of id by pref" do
84
+ @client.send(:id_by_pref).should be_kind_of Hash
85
+ end
86
+ end
87
+
88
+ describe "#parse_area_table" do
89
+ context "when passed malformed hash response" do
90
+ it do
91
+ expect {
92
+ @client.send(:parse_area_table, {:unexpected => :hash})
93
+ }.to raise_error(WeatherHacker::Client::ParseError)
94
+ end
95
+ end
96
+ end
49
97
  end
@@ -18,4 +18,6 @@ Gem::Specification.new do |gem|
18
18
  gem.add_dependency 'rake', '>= 0.9.2'
19
19
  gem.add_dependency "httparty"
20
20
  gem.add_development_dependency "rspec"
21
+ gem.add_development_dependency "simplecov"
22
+ gem.add_development_dependency "simplecov-vim"
21
23
  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.1.0
4
+ version: 0.1.1
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: &70211207058840 !ruby/object:Gem::Requirement
16
+ requirement: &70218237022340 !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: *70211207058840
24
+ version_requirements: *70218237022340
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: httparty
27
- requirement: &70211207058420 !ruby/object:Gem::Requirement
27
+ requirement: &70218237021920 !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: *70211207058420
35
+ version_requirements: *70218237021920
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70211207057960 !ruby/object:Gem::Requirement
38
+ requirement: &70218237021460 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,7 +43,29 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70211207057960
46
+ version_requirements: *70218237021460
47
+ - !ruby/object:Gem::Dependency
48
+ name: simplecov
49
+ requirement: &70218237021040 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70218237021040
58
+ - !ruby/object:Gem::Dependency
59
+ name: simplecov-vim
60
+ requirement: &70218237020620 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *70218237020620
47
69
  description: Library for Livedoor Weather Web Service
48
70
  email:
49
71
  - r7kamura@gmail.com
@@ -81,7 +103,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
81
103
  version: '0'
82
104
  segments:
83
105
  - 0
84
- hash: -2444633236054431010
106
+ hash: -1826125772160872950
85
107
  required_rubygems_version: !ruby/object:Gem::Requirement
86
108
  none: false
87
109
  requirements:
@@ -90,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
112
  version: '0'
91
113
  segments:
92
114
  - 0
93
- hash: -2444633236054431010
115
+ hash: -1826125772160872950
94
116
  requirements: []
95
117
  rubyforge_project:
96
118
  rubygems_version: 1.8.15