iarea 0.4.2 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -22,15 +22,11 @@ module Iarea
22
22
  # Find area by <tt>areacode</tt>
23
23
  def find(areacode)
24
24
  if area = @@areas[areacode]
25
- return area
25
+ area
26
+ elsif area_data = DB['area'][areacode]
27
+ @@areas[areacode] ||= new(area_data)
26
28
  else
27
- if area_data = DB['area'][areacode]
28
- area = new(area_data)
29
- @@areas[areacode] = area
30
- return area
31
- else
32
- return nil
33
- end
29
+ nil
34
30
  end
35
31
  end
36
32
 
@@ -16,7 +16,13 @@ module Iarea
16
16
  class << self
17
17
  # Find a prefecture by <tt>id</tt>
18
18
  def find(id)
19
- @@prefectures[id.to_i] ||= new DB['prefecture'][id.to_i]
19
+ if prefecture = @@prefectures[id.to_i]
20
+ prefecture
21
+ elsif prefecture_data = DB['prefecture'][id.to_i]
22
+ @@prefectures[id.to_i] ||= new(prefecture_data)
23
+ else
24
+ nil
25
+ end
20
26
  end
21
27
 
22
28
  # All prefectures
@@ -1,3 +1,3 @@
1
1
  module Iarea
2
- VERSION = "0.4.2"
2
+ VERSION = "0.5.0"
3
3
  end
@@ -15,7 +15,13 @@ module Iarea
15
15
  class << self
16
16
  # Find a zone by <tt>id</tt>
17
17
  def find(id)
18
- @@zones[id.to_i] ||= new DB['zone'][id.to_i]
18
+ if zone = @@zones[id.to_i]
19
+ zone
20
+ elsif zone_data = DB['zone'][id.to_i]
21
+ @@zones[id.to_i] ||= new(zone_data)
22
+ else
23
+ nil
24
+ end
19
25
  end
20
26
 
21
27
  # All zones
@@ -58,4 +58,10 @@ describe Iarea::Area do
58
58
  subject { Iarea::Area.find("06304") }
59
59
  its(:name) { should == "新宿1〜2丁目" }
60
60
  end
61
+
62
+ context 'finding by invalid id' do
63
+ it do
64
+ Iarea::Area.find(-1).should be_nil
65
+ end
66
+ end
61
67
  end
@@ -35,4 +35,10 @@ describe Iarea::Prefecture do
35
35
  it '#all' do
36
36
  Iarea::Prefecture.all.should == (1..47).map {|i| Iarea::Prefecture.find(i)}
37
37
  end
38
+
39
+ context 'finding by invalid id' do
40
+ it do
41
+ Iarea::Prefecture.find(-1).should be_nil
42
+ end
43
+ end
38
44
  end
@@ -35,4 +35,10 @@ describe Iarea::Zone do
35
35
  it '#all' do
36
36
  Iarea::Zone.all.should == (1..9).map {|i| Iarea::Zone.find(i)}
37
37
  end
38
+
39
+ context 'finding by invalid id' do
40
+ it do
41
+ Iarea::Zone.find(-1).should be_nil
42
+ end
43
+ end
38
44
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iarea
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-06 00:00:00.000000000 +09:00
13
- default_executable:
12
+ date: 2011-09-28 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: msgpack
17
- requirement: &2157575000 !ruby/object:Gem::Requirement
16
+ requirement: &2158142580 !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ! '>='
@@ -22,10 +21,10 @@ dependencies:
22
21
  version: '0'
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *2157575000
24
+ version_requirements: *2158142580
26
25
  - !ruby/object:Gem::Dependency
27
26
  name: rspec
28
- requirement: &2157574580 !ruby/object:Gem::Requirement
27
+ requirement: &2158142160 !ruby/object:Gem::Requirement
29
28
  none: false
30
29
  requirements:
31
30
  - - ! '>='
@@ -33,10 +32,10 @@ dependencies:
33
32
  version: '0'
34
33
  type: :development
35
34
  prerelease: false
36
- version_requirements: *2157574580
35
+ version_requirements: *2158142160
37
36
  - !ruby/object:Gem::Dependency
38
37
  name: rdoc
39
- requirement: &2157574160 !ruby/object:Gem::Requirement
38
+ requirement: &2158141740 !ruby/object:Gem::Requirement
40
39
  none: false
41
40
  requirements:
42
41
  - - ! '>='
@@ -44,10 +43,10 @@ dependencies:
44
43
  version: '0'
45
44
  type: :development
46
45
  prerelease: false
47
- version_requirements: *2157574160
46
+ version_requirements: *2158141740
48
47
  - !ruby/object:Gem::Dependency
49
48
  name: rake
50
- requirement: &2157573740 !ruby/object:Gem::Requirement
49
+ requirement: &2158141320 !ruby/object:Gem::Requirement
51
50
  none: false
52
51
  requirements:
53
52
  - - ! '>='
@@ -55,10 +54,10 @@ dependencies:
55
54
  version: '0'
56
55
  type: :development
57
56
  prerelease: false
58
- version_requirements: *2157573740
57
+ version_requirements: *2158141320
59
58
  - !ruby/object:Gem::Dependency
60
59
  name: bundler
61
- requirement: &2157573320 !ruby/object:Gem::Requirement
60
+ requirement: &2158140900 !ruby/object:Gem::Requirement
62
61
  none: false
63
62
  requirements:
64
63
  - - ! '>='
@@ -66,7 +65,7 @@ dependencies:
66
65
  version: '0'
67
66
  type: :development
68
67
  prerelease: false
69
- version_requirements: *2157573320
68
+ version_requirements: *2158140900
70
69
  description: A library for DoCoMo Open Iarea.
71
70
  email:
72
71
  - dara@shidara.net
@@ -99,7 +98,6 @@ files:
99
98
  - spec/iarea/zone_spec.rb
100
99
  - spec/spec_helper.rb
101
100
  - tools/generate.rb
102
- has_rdoc: true
103
101
  homepage: http://github.com/darashi/iarea
104
102
  licenses: []
105
103
  post_install_message:
@@ -120,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
118
  version: '0'
121
119
  requirements: []
122
120
  rubyforge_project: iarea
123
- rubygems_version: 1.6.1
121
+ rubygems_version: 1.8.3
124
122
  signing_key:
125
123
  specification_version: 3
126
124
  summary: A library for DoCoMo Open Iarea.