jp_prefecture 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +1 -1
- data/.travis.yml +1 -1
- data/CHANGELOG.md +4 -0
- data/README.md +16 -16
- data/Rakefile +3 -3
- data/data/prefecture.yml +47 -0
- data/data/zip.yml +1 -1
- data/jp_prefecture.gemspec +9 -9
- data/lib/jp_prefecture/prefecture.rb +6 -4
- data/lib/jp_prefecture/version.rb +1 -1
- data/spec/base_spec.rb +14 -14
- data/spec/config_spec.rb +1 -1
- data/spec/jp_prefecture_spec.rb +3 -3
- data/spec/mapping_spec.rb +1 -1
- data/spec/prefecture_spec.rb +22 -20
- data/spec/spec_helper.rb +2 -2
- data/spec/zip_mapping_spec.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1a6fc2c7b381afa449625bf8295c9dde2e89025e
|
4
|
+
data.tar.gz: 8860880c91399cf152aed754e2206f48c399ed1e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2366a6fc0884ef37a5bb2f687d5afeb91397e6c18bc4c62edff017154039a3cf29801026b0b94a81c09cec47dc214612a27f3349b365ebdebd151d07c2b7a90a
|
7
|
+
data.tar.gz: 412f4586f1b44c6c2c13e22da5d906c85459f292849fed471945de8ec704279b0e6474c04be2f3fc422dfaded9f9770be5d3cadafdd772add8a78c6af9b9c88c
|
data/.rspec
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
--
|
1
|
+
--color
|
2
2
|
--format documentation
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## 0.8.0 (Sep 07, 2014)
|
2
|
+
|
3
|
+
* 都道府県情報に八地方区分情報を追加 (PR [#14](https://github.com/chocoby/jp_prefecture/pull/14)/[@kkosuge](https://github.com/kkosuge))
|
4
|
+
|
1
5
|
## 0.7.0 (Jun 18, 2014)
|
2
6
|
|
3
7
|
* 都道府県名にひらがな、カタカナを追加 (PR [#12](https://github.com/chocoby/jp_prefecture/pull/12)/[@yukihr](https://github.com/yukihr))
|
data/README.md
CHANGED
@@ -51,11 +51,11 @@ require 'jp_prefecture'
|
|
51
51
|
|
52
52
|
### 都道府県コードから都道府県を検索
|
53
53
|
|
54
|
-
|
54
|
+
都道府県コードを渡すと、都道府県コードから都道府県を検索します:
|
55
55
|
|
56
56
|
```ruby
|
57
57
|
pref = JpPrefecture::Prefecture.find 13
|
58
|
-
# => #<JpPrefecture::Prefecture:
|
58
|
+
# => #<JpPrefecture::Prefecture:0x007fceb11927d8 @code=13, @name="東京都", @name_e="Tokyo", @name_h="とうきょうと", @name_k="トウキョウト", @zips=[1000000..2080035], @area="関東">
|
59
59
|
pref.code
|
60
60
|
# => 13
|
61
61
|
pref.name
|
@@ -66,9 +66,11 @@ pref.name_h
|
|
66
66
|
# => "とうきょうと"
|
67
67
|
pref.name_k
|
68
68
|
# => "トウキョウト"
|
69
|
+
pref.area
|
70
|
+
# => "関東"
|
69
71
|
```
|
70
72
|
|
71
|
-
|
73
|
+
以下のように書くことも可能です:
|
72
74
|
|
73
75
|
```ruby
|
74
76
|
JpPrefecture::Prefecture.find code: 13
|
@@ -78,32 +80,21 @@ JpPrefecture::Prefecture.find code: 13
|
|
78
80
|
|
79
81
|
```ruby
|
80
82
|
JpPrefecture::Prefecture.find name: "東京都"
|
81
|
-
# => #<JpPrefecture::Prefecture:0x007fe7bb033040 @code=13, @name="東京都", @name_e="Tokyo", @name_h="とうきょうと", @name_k="トウキョウト", @zips=[1000000..2080035]>
|
82
|
-
|
83
83
|
JpPrefecture::Prefecture.find name: "Tokyo"
|
84
|
-
# => #<JpPrefecture::Prefecture:0x007fe7bb032758 @code=13, @name="東京都", @name_e="Tokyo", @name_h="とうきょうと", @name_k="トウキョウト", @zips=[1000000..2080035]>
|
85
|
-
|
86
84
|
JpPrefecture::Prefecture.find name: "tokyo"
|
87
|
-
# => #<JpPrefecture::Prefecture:0x007fe7bb031e70 @code=13, @name="東京都", @name_e="Tokyo", @name_h="とうきょうと", @name_k="トウキョウト", @zips=[1000000..2080035]>
|
88
|
-
|
89
85
|
JpPrefecture::Prefecture.find name: "トウキョウト"
|
90
|
-
# => #<JpPrefecture::Prefecture:0x007f8cc2038210 @code=13, @name="東京都", @name_e="Tokyo", @name_h="とうきょうと", @name_k="トウキョウト", @zips=[1000000..2080035]>
|
91
|
-
|
92
86
|
JpPrefecture::Prefecture.find name: "とうきょうと"
|
93
|
-
# => #<JpPrefecture::Prefecture:0x007f8cc2033760 @code=13, @name="東京都", @name_e="Tokyo", @name_h="とうきょうと", @name_k="トウキョウト", @zips=[1000000..2080035]>
|
94
|
-
|
95
87
|
JpPrefecture::Prefecture.find name: "東京"
|
96
|
-
# => #<JpPrefecture::Prefecture:0x007fe7bb0305c0 @code=13, @name="東京都", @name_e="Tokyo", @name_h="とうきょうと", @name_k="トウキョウト", @zips=[1000000..2080035]>
|
97
88
|
```
|
98
89
|
|
99
90
|
### 都道府県の一覧を取得
|
100
91
|
|
101
92
|
```ruby
|
102
93
|
JpPrefecture::Prefecture.all
|
103
|
-
# => [#<JpPrefecture::Prefecture:
|
94
|
+
# => [#<JpPrefecture::Prefecture:0x007fceb119a2a8 @code=1, @name="北海道", @name_e="Hokkaido", @name_h="ほっかいどう", @name_k="ホッカイドウ", @zips=[10000..70895, 400000..996509], @area="北海道">, ...]
|
104
95
|
```
|
105
96
|
|
106
|
-
### Rails(ActiveRecord) で使用する
|
97
|
+
### Rails (ActiveRecord) で使用する
|
107
98
|
|
108
99
|
`ActiveRecord::Base` を継承した Model で、都道府県コードを扱うことができます。
|
109
100
|
|
@@ -200,6 +191,15 @@ GitHub の [Issues](https://github.com/chocoby/jp_prefecture/issues) を参照
|
|
200
191
|
4. Push to the branch (`git push origin my-new-feature`)
|
201
192
|
5. Create new Pull Request
|
202
193
|
|
194
|
+
## テスト
|
195
|
+
|
196
|
+
```
|
197
|
+
git clone https://github.com/chocoby/jp_prefecture.git
|
198
|
+
cd jp_prefecture
|
199
|
+
bundle install --path .bundle
|
200
|
+
bundle exec rspec
|
201
|
+
```
|
202
|
+
|
203
203
|
## GitHub
|
204
204
|
|
205
205
|
https://github.com/chocoby/jp_prefecture
|
data/Rakefile
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
# coding: utf-8
|
3
3
|
require "bundler/gem_tasks"
|
4
4
|
|
5
|
-
task :
|
5
|
+
task default: [:spec]
|
6
6
|
begin
|
7
7
|
require 'rspec/core/rake_task'
|
8
8
|
RSpec::Core::RakeTask.new(:spec) do |spec|
|
9
9
|
spec.pattern = 'spec/**/*_spec.rb'
|
10
|
-
spec.rspec_opts =
|
10
|
+
spec.rspec_opts = %w(--format documentation --color)
|
11
11
|
end
|
12
12
|
rescue LoadError => e
|
13
13
|
end
|
@@ -65,7 +65,7 @@ task :create_zips do
|
|
65
65
|
|
66
66
|
# save result
|
67
67
|
File.open('data/zip.yml', 'w') do |file|
|
68
|
-
file.write "# {:
|
68
|
+
file.write "# { prefecture_code: [[from_zip_1, to_zip_1], [from_zip_2, to_zip_2], ...], ... }\n"
|
69
69
|
file.write prefectures_to_zip.to_yaml
|
70
70
|
end
|
71
71
|
|
data/data/prefecture.yml
CHANGED
@@ -6,233 +6,280 @@
|
|
6
6
|
:name_e: hokkaido
|
7
7
|
:name_h: ほっかいどう
|
8
8
|
:name_k: ホッカイドウ
|
9
|
+
:area: 北海道
|
9
10
|
2:
|
10
11
|
:name: 青森県
|
11
12
|
:name_e: aomori
|
12
13
|
:name_h: あおもりけん
|
13
14
|
:name_k: アオモリケン
|
15
|
+
:area: 東北
|
14
16
|
3:
|
15
17
|
:name: 岩手県
|
16
18
|
:name_e: iwate
|
17
19
|
:name_h: いわてけん
|
18
20
|
:name_k: イワテケン
|
21
|
+
:area: 東北
|
19
22
|
4:
|
20
23
|
:name: 宮城県
|
21
24
|
:name_e: miyagi
|
22
25
|
:name_h: みやぎけん
|
23
26
|
:name_k: ミヤギケン
|
27
|
+
:area: 東北
|
24
28
|
5:
|
25
29
|
:name: 秋田県
|
26
30
|
:name_e: akita
|
27
31
|
:name_h: あきたけん
|
28
32
|
:name_k: アキタケン
|
33
|
+
:area: 東北
|
29
34
|
6:
|
30
35
|
:name: 山形県
|
31
36
|
:name_e: yamagata
|
32
37
|
:name_h: やまがたけん
|
33
38
|
:name_k: ヤマガタケン
|
39
|
+
:area: 東北
|
34
40
|
7:
|
35
41
|
:name: 福島県
|
36
42
|
:name_e: fukushima
|
37
43
|
:name_h: ふくしまけん
|
38
44
|
:name_k: フクシマケン
|
45
|
+
:area: 東北
|
39
46
|
8:
|
40
47
|
:name: 茨城県
|
41
48
|
:name_e: ibaraki
|
42
49
|
:name_h: いばらきけん
|
43
50
|
:name_k: イバラキケン
|
51
|
+
:area: 関東
|
44
52
|
9:
|
45
53
|
:name: 栃木県
|
46
54
|
:name_e: tochigi
|
47
55
|
:name_h: とちぎけん
|
48
56
|
:name_k: トチギケン
|
57
|
+
:area: 関東
|
49
58
|
10:
|
50
59
|
:name: 群馬県
|
51
60
|
:name_e: gunma
|
52
61
|
:name_h: ぐんまけん
|
53
62
|
:name_k: グンマケン
|
63
|
+
:area: 関東
|
54
64
|
11:
|
55
65
|
:name: 埼玉県
|
56
66
|
:name_e: saitama
|
57
67
|
:name_h: さいたまけん
|
58
68
|
:name_k: サイタマケン
|
69
|
+
:area: 関東
|
59
70
|
12:
|
60
71
|
:name: 千葉県
|
61
72
|
:name_e: chiba
|
62
73
|
:name_h: ちばけん
|
63
74
|
:name_k: チバケン
|
75
|
+
:area: 関東
|
64
76
|
13:
|
65
77
|
:name: 東京都
|
66
78
|
:name_e: tokyo
|
67
79
|
:name_h: とうきょうと
|
68
80
|
:name_k: トウキョウト
|
81
|
+
:area: 関東
|
69
82
|
14:
|
70
83
|
:name: 神奈川県
|
71
84
|
:name_e: kanagawa
|
72
85
|
:name_h: かながわけん
|
73
86
|
:name_k: カナガワケン
|
87
|
+
:area: 関東
|
74
88
|
15:
|
75
89
|
:name: 新潟県
|
76
90
|
:name_e: niigata
|
77
91
|
:name_h: にいがたけん
|
78
92
|
:name_k: ニイガタケン
|
93
|
+
:area: 中部
|
79
94
|
16:
|
80
95
|
:name: 富山県
|
81
96
|
:name_e: toyama
|
82
97
|
:name_h: とやまけん
|
83
98
|
:name_k: トヤマケン
|
99
|
+
:area: 中部
|
84
100
|
17:
|
85
101
|
:name: 石川県
|
86
102
|
:name_e: ishikawa
|
87
103
|
:name_h: いしかわけん
|
88
104
|
:name_k: イシカワケン
|
105
|
+
:area: 中部
|
89
106
|
18:
|
90
107
|
:name: 福井県
|
91
108
|
:name_e: fukui
|
92
109
|
:name_h: ふくいけん
|
93
110
|
:name_k: フクイケン
|
111
|
+
:area: 中部
|
94
112
|
19:
|
95
113
|
:name: 山梨県
|
96
114
|
:name_e: yamanashi
|
97
115
|
:name_h: やまなしけん
|
98
116
|
:name_k: ヤマナシケン
|
117
|
+
:area: 中部
|
99
118
|
20:
|
100
119
|
:name: 長野県
|
101
120
|
:name_e: nagano
|
102
121
|
:name_h: ながのけん
|
103
122
|
:name_k: ナガノケン
|
123
|
+
:area: 中部
|
104
124
|
21:
|
105
125
|
:name: 岐阜県
|
106
126
|
:name_e: gifu
|
107
127
|
:name_h: ぎふけん
|
108
128
|
:name_k: ギフケン
|
129
|
+
:area: 中部
|
109
130
|
22:
|
110
131
|
:name: 静岡県
|
111
132
|
:name_e: shizuoka
|
112
133
|
:name_h: しずおかけん
|
113
134
|
:name_k: シズオカケン
|
135
|
+
:area: 中部
|
114
136
|
23:
|
115
137
|
:name: 愛知県
|
116
138
|
:name_e: aichi
|
117
139
|
:name_h: あいちけん
|
118
140
|
:name_k: アイチケン
|
141
|
+
:area: 中部
|
119
142
|
24:
|
120
143
|
:name: 三重県
|
121
144
|
:name_e: mie
|
122
145
|
:name_h: みえけん
|
123
146
|
:name_k: ミエケン
|
147
|
+
:area: 関西
|
124
148
|
25:
|
125
149
|
:name: 滋賀県
|
126
150
|
:name_e: shiga
|
127
151
|
:name_h: しがけん
|
128
152
|
:name_k: シガケン
|
153
|
+
:area: 関西
|
129
154
|
26:
|
130
155
|
:name: 京都府
|
131
156
|
:name_e: kyoto
|
132
157
|
:name_h: きょうとふ
|
133
158
|
:name_k: キョウトフ
|
159
|
+
:area: 関西
|
134
160
|
27:
|
135
161
|
:name: 大阪府
|
136
162
|
:name_e: osaka
|
137
163
|
:name_h: おおさかふ
|
138
164
|
:name_k: オオサカフ
|
165
|
+
:area: 関西
|
139
166
|
28:
|
140
167
|
:name: 兵庫県
|
141
168
|
:name_e: hyogo
|
142
169
|
:name_h: ひょうごけん
|
143
170
|
:name_k: ヒョウゴケン
|
171
|
+
:area: 関西
|
144
172
|
29:
|
145
173
|
:name: 奈良県
|
146
174
|
:name_e: nara
|
147
175
|
:name_h: ならけん
|
148
176
|
:name_k: ナラケン
|
177
|
+
:area: 関西
|
149
178
|
30:
|
150
179
|
:name: 和歌山県
|
151
180
|
:name_e: wakayama
|
152
181
|
:name_h: わかやまけん
|
153
182
|
:name_k: ワカヤマケン
|
183
|
+
:area: 関西
|
154
184
|
31:
|
155
185
|
:name: 鳥取県
|
156
186
|
:name_e: tottori
|
157
187
|
:name_h: とっとりけん
|
158
188
|
:name_k: トットリケン
|
189
|
+
:area: 中国
|
159
190
|
32:
|
160
191
|
:name: 島根県
|
161
192
|
:name_e: shimane
|
162
193
|
:name_h: しまねけん
|
163
194
|
:name_k: シマネケン
|
195
|
+
:area: 中国
|
164
196
|
33:
|
165
197
|
:name: 岡山県
|
166
198
|
:name_e: okayama
|
167
199
|
:name_h: おかやまけん
|
168
200
|
:name_k: オカヤマケン
|
201
|
+
:area: 中国
|
169
202
|
34:
|
170
203
|
:name: 広島県
|
171
204
|
:name_e: hiroshima
|
172
205
|
:name_h: ひろしまけん
|
173
206
|
:name_k: ヒロシマケン
|
207
|
+
:area: 中国
|
174
208
|
35:
|
175
209
|
:name: 山口県
|
176
210
|
:name_e: yamaguchi
|
177
211
|
:name_h: やまぐちけん
|
178
212
|
:name_k: ヤマグチケン
|
213
|
+
:area: 中国
|
179
214
|
36:
|
180
215
|
:name: 徳島県
|
181
216
|
:name_e: tokushima
|
182
217
|
:name_h: とくしまけん
|
183
218
|
:name_k: トクシマケン
|
219
|
+
:area: 四国
|
184
220
|
37:
|
185
221
|
:name: 香川県
|
186
222
|
:name_e: kagawa
|
187
223
|
:name_h: かがわけん
|
188
224
|
:name_k: カガワケン
|
225
|
+
:area: 四国
|
189
226
|
38:
|
190
227
|
:name: 愛媛県
|
191
228
|
:name_e: ehime
|
192
229
|
:name_h: えひめけん
|
193
230
|
:name_k: エヒメケン
|
231
|
+
:area: 四国
|
194
232
|
39:
|
195
233
|
:name: 高知県
|
196
234
|
:name_e: kochi
|
197
235
|
:name_h: こうちけん
|
198
236
|
:name_k: コウチケン
|
237
|
+
:area: 四国
|
199
238
|
40:
|
200
239
|
:name: 福岡県
|
201
240
|
:name_e: fukuoka
|
202
241
|
:name_h: ふくおかけん
|
203
242
|
:name_k: フクオカケン
|
243
|
+
:area: 九州
|
204
244
|
41:
|
205
245
|
:name: 佐賀県
|
206
246
|
:name_e: saga
|
207
247
|
:name_h: さがけん
|
208
248
|
:name_k: サガケン
|
249
|
+
:area: 九州
|
209
250
|
42:
|
210
251
|
:name: 長崎県
|
211
252
|
:name_e: nagasaki
|
212
253
|
:name_h: ながさきけん
|
213
254
|
:name_k: ナガサキケン
|
255
|
+
:area: 九州
|
214
256
|
43:
|
215
257
|
:name: 熊本県
|
216
258
|
:name_e: kumamoto
|
217
259
|
:name_h: くまもとけん
|
218
260
|
:name_k: クマモトケン
|
261
|
+
:area: 九州
|
219
262
|
44:
|
220
263
|
:name: 大分県
|
221
264
|
:name_e: oita
|
222
265
|
:name_h: おおいたけん
|
223
266
|
:name_k: オオイタケン
|
267
|
+
:area: 九州
|
224
268
|
45:
|
225
269
|
:name: 宮崎県
|
226
270
|
:name_e: miyazaki
|
227
271
|
:name_h: みやざきけん
|
228
272
|
:name_k: ミヤザキケン
|
273
|
+
:area: 九州
|
229
274
|
46:
|
230
275
|
:name: 鹿児島県
|
231
276
|
:name_e: kagoshima
|
232
277
|
:name_h: かごしまけん
|
233
278
|
:name_k: カゴシマケン
|
279
|
+
:area: 九州
|
234
280
|
47:
|
235
281
|
:name: 沖縄県
|
236
282
|
:name_e: okinawa
|
237
283
|
:name_h: おきなわけん
|
238
284
|
:name_k: オキナワケン
|
285
|
+
:area: 九州
|
data/data/zip.yml
CHANGED
data/jp_prefecture.gemspec
CHANGED
@@ -2,21 +2,21 @@
|
|
2
2
|
require File.expand_path('../lib/jp_prefecture/version', __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = [
|
6
|
-
gem.email = [
|
5
|
+
gem.authors = ['chocoby']
|
6
|
+
gem.email = ['chocoby@gmail.com']
|
7
7
|
gem.summary = %q{Convert japan prefecture code into prefecture name}
|
8
8
|
gem.description = %q{Convert japan prefecture code(JIS X 0402 based) into prefecture name.}
|
9
|
-
gem.homepage =
|
9
|
+
gem.homepage = 'https://github.com/chocoby/jp_prefecture'
|
10
10
|
|
11
11
|
gem.files = `git ls-files`.split($\)
|
12
12
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
13
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
-
gem.name =
|
15
|
-
gem.require_paths = [
|
14
|
+
gem.name = 'jp_prefecture'
|
15
|
+
gem.require_paths = ['lib']
|
16
16
|
gem.version = JpPrefecture::VERSION
|
17
17
|
|
18
|
-
gem.add_development_dependency
|
19
|
-
gem.add_development_dependency
|
20
|
-
gem.add_development_dependency
|
21
|
-
gem.add_development_dependency
|
18
|
+
gem.add_development_dependency 'rake'
|
19
|
+
gem.add_development_dependency 'rspec', '~> 3.1'
|
20
|
+
gem.add_development_dependency 'activerecord', '>= 3.2.0'
|
21
|
+
gem.add_development_dependency 'sqlite3'
|
22
22
|
end
|
@@ -6,7 +6,7 @@ module JpPrefecture
|
|
6
6
|
# 都道府県のコードと名前を扱うクラス
|
7
7
|
class Prefecture
|
8
8
|
|
9
|
-
attr_accessor :code, :name, :name_e, :name_h, :name_k, :zips
|
9
|
+
attr_accessor :code, :name, :name_e, :name_h, :name_k, :zips, :area
|
10
10
|
|
11
11
|
# 配列から都道府県クラスを生成
|
12
12
|
#
|
@@ -19,8 +19,9 @@ module JpPrefecture
|
|
19
19
|
# @param name_e [String] 都道府県名(英語表記)
|
20
20
|
# @param optional name_h [String] 都道府県名(ひらがな表記)
|
21
21
|
# @param optional name_k [String] 都道府県名(カタカナ表記)
|
22
|
+
# @param optional area [String] 地方名
|
22
23
|
# @param zips [Array] 郵便番号の配列 (array of ranges, can be used in ARel, e.g. User.where(zip: prefecture.zips))
|
23
|
-
def self.build(code, name, name_e, name_h = nil, name_k = nil)
|
24
|
+
def self.build(code, name, name_e, name_h = nil, name_k = nil, area = nil)
|
24
25
|
pref = self.new
|
25
26
|
|
26
27
|
pref.code = code
|
@@ -29,6 +30,7 @@ module JpPrefecture
|
|
29
30
|
pref.name_h = name_h
|
30
31
|
pref.name_k = name_k
|
31
32
|
pref.zips = ZipMapping.data[code]
|
33
|
+
pref.area = area
|
32
34
|
|
33
35
|
pref
|
34
36
|
end
|
@@ -80,7 +82,7 @@ module JpPrefecture
|
|
80
82
|
|
81
83
|
self.build(code,
|
82
84
|
names[:name], names[:name_e],
|
83
|
-
names[:name_h], names[:name_k])
|
85
|
+
names[:name_h], names[:name_k], names[:area])
|
84
86
|
end
|
85
87
|
|
86
88
|
# すべての都道府県クラスを返す
|
@@ -101,7 +103,7 @@ module JpPrefecture
|
|
101
103
|
names = pref[1]
|
102
104
|
self.build(pref[0],
|
103
105
|
names[:name], names[:name_e],
|
104
|
-
names[:name_h], names[:name_k])
|
106
|
+
names[:name_h], names[:name_k], names[:area])
|
105
107
|
end
|
106
108
|
end
|
107
109
|
|
data/spec/base_spec.rb
CHANGED
@@ -12,11 +12,11 @@ describe JpPrefecture::Base do
|
|
12
12
|
jp_prefecture :prefecture_code
|
13
13
|
end
|
14
14
|
|
15
|
-
klass.new(:
|
15
|
+
klass.new(prefecture_code: 1)
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'prefecture_code のコードが変換できること' do
|
19
|
-
model_class.prefecture.name.
|
19
|
+
expect(model_class.prefecture.name).to eq '北海道'
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -28,11 +28,11 @@ describe JpPrefecture::Base do
|
|
28
28
|
jp_prefecture :prefecture_id
|
29
29
|
end
|
30
30
|
|
31
|
-
klass.new(:
|
31
|
+
klass.new(prefecture_id: 1)
|
32
32
|
end
|
33
33
|
|
34
34
|
it 'prefecture_id のコードが変換できること' do
|
35
|
-
model_class.prefecture.name.
|
35
|
+
expect(model_class.prefecture.name).to eq '北海道'
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -43,14 +43,14 @@ describe JpPrefecture::Base do
|
|
43
43
|
klass = Class.new(ActiveRecord::Base) do
|
44
44
|
self.table_name = :places
|
45
45
|
include JpPrefecture
|
46
|
-
jp_prefecture :prefecture_code, :
|
46
|
+
jp_prefecture :prefecture_code, method_name: :prefecture_method
|
47
47
|
end
|
48
48
|
|
49
|
-
klass.new(:
|
49
|
+
klass.new(prefecture_code: 1)
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'prefecture_method で結果が参照できること' do
|
53
|
-
model_class.prefecture_method.name.
|
53
|
+
expect(model_class.prefecture_method.name).to eq '北海道'
|
54
54
|
end
|
55
55
|
end
|
56
56
|
end
|
@@ -65,16 +65,16 @@ describe JpPrefecture::Base do
|
|
65
65
|
end
|
66
66
|
|
67
67
|
context '都道府県が見つかった場合' do
|
68
|
-
let(:model_class) { klass.new(:
|
69
|
-
it { model_class.
|
70
|
-
it { model_class.prefecture.
|
71
|
-
it { model_class.prefecture.name.
|
68
|
+
let(:model_class) { klass.new(prefecture_code: 1) }
|
69
|
+
it { expect(model_class).to respond_to(:prefecture) }
|
70
|
+
it { expect(model_class.prefecture).to be_an_instance_of(JpPrefecture::Prefecture) }
|
71
|
+
it { expect(model_class.prefecture.name).to eq '北海道' }
|
72
72
|
end
|
73
73
|
|
74
74
|
context '都道府県が見つからなかった場合' do
|
75
|
-
let(:model_class) { klass.new(:
|
76
|
-
it { model_class.
|
77
|
-
it { model_class.prefecture.
|
75
|
+
let(:model_class) { klass.new(prefecture_code: 99) }
|
76
|
+
it { expect(model_class).to respond_to(:prefecture) }
|
77
|
+
it { expect(model_class.prefecture).to be_nil }
|
78
78
|
end
|
79
79
|
end
|
80
80
|
end
|
data/spec/config_spec.rb
CHANGED
data/spec/jp_prefecture_spec.rb
CHANGED
@@ -9,12 +9,12 @@ describe JpPrefecture do
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
it {
|
12
|
+
it { is_expected.to respond_to(:jp_prefecture) }
|
13
13
|
end
|
14
14
|
|
15
15
|
describe 'include されていない' do
|
16
16
|
subject { Class.new(ActiveRecord::Base) }
|
17
|
-
it {
|
17
|
+
it { is_expected.not_to respond_to(:jp_prefecture) }
|
18
18
|
end
|
19
19
|
|
20
20
|
describe '.setup' do
|
@@ -31,6 +31,6 @@ describe JpPrefecture do
|
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
it { JpPrefecture::Mapping.data.count.
|
34
|
+
it { expect(JpPrefecture::Mapping.data.count).to eq 48 }
|
35
35
|
end
|
36
36
|
end
|
data/spec/mapping_spec.rb
CHANGED
data/spec/prefecture_spec.rb
CHANGED
@@ -3,30 +3,32 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
describe JpPrefecture::Prefecture do
|
5
5
|
describe '.build' do
|
6
|
-
let(:pref) { JpPrefecture::Prefecture.build(1, '北海道', 'Hokkaido', 'ほっかいどう', 'ホッカイドウ') }
|
7
|
-
it { pref.code.
|
8
|
-
it { pref.name.
|
9
|
-
it { pref.name_e.
|
10
|
-
it { pref.name_h.
|
11
|
-
it { pref.name_k.
|
12
|
-
it { pref.zips.
|
6
|
+
let(:pref) { JpPrefecture::Prefecture.build(1, '北海道', 'Hokkaido', 'ほっかいどう', 'ホッカイドウ', '北海道') }
|
7
|
+
it { expect(pref.code).to eq 1 }
|
8
|
+
it { expect(pref.name).to eq '北海道' }
|
9
|
+
it { expect(pref.name_e).to eq 'Hokkaido' }
|
10
|
+
it { expect(pref.name_h).to eq 'ほっかいどう' }
|
11
|
+
it { expect(pref.name_k).to eq 'ホッカイドウ' }
|
12
|
+
it { expect(pref.zips).to eq [10000..70895, 400000..996509] }
|
13
|
+
it { expect(pref.area).to eq '北海道' }
|
13
14
|
end
|
14
15
|
|
15
16
|
describe '.find' do
|
16
17
|
describe '検索結果について' do
|
17
18
|
shared_examples "都道府県が見つかる" do |arg|
|
18
19
|
let(:pref) { JpPrefecture::Prefecture.find(arg) }
|
19
|
-
it { pref.code.
|
20
|
-
it { pref.name.
|
21
|
-
it { pref.name_e.
|
22
|
-
it { pref.name_h.
|
23
|
-
it { pref.name_k.
|
24
|
-
it { pref.zips.
|
20
|
+
it { expect(pref.code).to eq 1 }
|
21
|
+
it { expect(pref.name).to eq '北海道' }
|
22
|
+
it { expect(pref.name_e).to eq 'Hokkaido' }
|
23
|
+
it { expect(pref.name_h).to eq 'ほっかいどう' }
|
24
|
+
it { expect(pref.name_k).to eq 'ホッカイドウ' }
|
25
|
+
it { expect(pref.zips).to eq [10000..70895, 400000..996509] }
|
26
|
+
it { expect(pref.area).to eq '北海道' }
|
25
27
|
end
|
26
28
|
|
27
29
|
shared_examples '都道府県が見つからない' do |arg|
|
28
30
|
let(:pref) { JpPrefecture::Prefecture.find(arg) }
|
29
|
-
it { pref.
|
31
|
+
it { expect(pref).to be_nil }
|
30
32
|
end
|
31
33
|
|
32
34
|
describe '都道府県コード' do
|
@@ -107,7 +109,7 @@ describe JpPrefecture::Prefecture do
|
|
107
109
|
it '値が変更されないこと' do
|
108
110
|
code = '1'
|
109
111
|
JpPrefecture::Prefecture.find(code)
|
110
|
-
code.
|
112
|
+
expect(code).to eq '1'
|
111
113
|
end
|
112
114
|
end
|
113
115
|
|
@@ -115,7 +117,7 @@ describe JpPrefecture::Prefecture do
|
|
115
117
|
it '値が変更されないこと' do
|
116
118
|
code = '1'
|
117
119
|
JpPrefecture::Prefecture.find(code: code)
|
118
|
-
code.
|
120
|
+
expect(code).to eq '1'
|
119
121
|
end
|
120
122
|
end
|
121
123
|
|
@@ -123,7 +125,7 @@ describe JpPrefecture::Prefecture do
|
|
123
125
|
it '値が変更されないこと' do
|
124
126
|
name = 'hokkaido'
|
125
127
|
JpPrefecture::Prefecture.find(name: name)
|
126
|
-
name.
|
128
|
+
expect(name).to eq 'hokkaido'
|
127
129
|
end
|
128
130
|
end
|
129
131
|
|
@@ -131,7 +133,7 @@ describe JpPrefecture::Prefecture do
|
|
131
133
|
it '値が変更されないこと' do
|
132
134
|
zip = '9999999'
|
133
135
|
JpPrefecture::Prefecture.find(zip: zip)
|
134
|
-
zip.
|
136
|
+
expect(zip).to eq '9999999'
|
135
137
|
end
|
136
138
|
end
|
137
139
|
end
|
@@ -139,9 +141,9 @@ describe JpPrefecture::Prefecture do
|
|
139
141
|
|
140
142
|
describe '.all' do
|
141
143
|
let(:prefs) { JpPrefecture::Prefecture.all }
|
142
|
-
it { prefs.first.
|
144
|
+
it { expect(prefs.first).to be_an_instance_of(JpPrefecture::Prefecture) }
|
143
145
|
it '都道府県の数が 47 であること' do
|
144
|
-
prefs.count.
|
146
|
+
expect(prefs.count).to eq 47
|
145
147
|
end
|
146
148
|
end
|
147
149
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -13,9 +13,9 @@ RSpec.configure do |config|
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def setup_db
|
16
|
-
ActiveRecord::Base.establish_connection :
|
16
|
+
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
|
17
17
|
|
18
|
-
ActiveRecord::Schema.define(:
|
18
|
+
ActiveRecord::Schema.define(version: 1) do
|
19
19
|
create_table :places do |t|
|
20
20
|
t.integer :prefecture_code
|
21
21
|
t.integer :prefecture_id
|
data/spec/zip_mapping_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jp_prefecture
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- chocoby
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '3.1'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: '3.1'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: activerecord
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|