jp_prefecture 0.8.1 → 1.0.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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +70 -13
- data/LICENSE +17 -18
- data/README.md +64 -51
- data/README_EN.md +227 -0
- data/data/zip.yml +10 -5
- data/lib/jp_prefecture.rb +6 -5
- data/lib/jp_prefecture/base.rb +3 -2
- data/lib/jp_prefecture/config.rb +2 -4
- data/lib/jp_prefecture/mapping.rb +2 -2
- data/lib/jp_prefecture/prefecture.rb +74 -101
- data/lib/jp_prefecture/prefecture/finder.rb +71 -0
- data/lib/jp_prefecture/version.rb +3 -1
- data/lib/jp_prefecture/zip_mapping.rb +9 -6
- metadata +107 -44
- data/.gitignore +0 -18
- data/.rspec +0 -2
- data/.travis.yml +0 -13
- data/.yardopts +0 -2
- data/Gemfile +0 -3
- data/Rakefile +0 -74
- data/jp_prefecture.gemspec +0 -23
- data/spec/base_spec.rb +0 -81
- data/spec/config_spec.rb +0 -18
- data/spec/fixtures/prefecture.yml +0 -148
- data/spec/jp_prefecture_spec.rb +0 -36
- data/spec/mapping_spec.rb +0 -10
- data/spec/prefecture_spec.rb +0 -163
- data/spec/spec_helper.rb +0 -35
- data/spec/zip_mapping_spec.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bc36935fbbb41fcb5ba3d46312f0c6200e3f1d0c713ecc6fe871804c565e58b2
|
4
|
+
data.tar.gz: ae4ca4e0d10a0177a038b18a4d413b83ac180270c219930df756f86d077dee44
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f2c6535136cfb3f1992ee02b07a5275a9fef64c8b43d4c9ac070fd7aa7b03cc396218a8bfa8a9e51d0fc5b930d341dc68aad2aea0fc40e459be1c444d17e115
|
7
|
+
data.tar.gz: 26081d3e210c27446dd8c3e97ec5b20dace2c6f279fab6a7e5a774f914c28703bada8cb7aaa58cb44eff5fd95068874d8272500b76a5bf385c64af1e5f03bd79
|
data/CHANGELOG.md
CHANGED
@@ -1,59 +1,116 @@
|
|
1
|
-
##
|
1
|
+
## Unreleased
|
2
|
+
|
3
|
+
## 1.0.0 (2021-02-24)
|
4
|
+
|
5
|
+
### Misc
|
6
|
+
|
7
|
+
* 毎週月曜日の 09:00 (JST) にテストを実行する (PR [#52](https://github.com/chocoby/jp_prefecture/pull/52)/[@chocoby](https://github.com/chocoby))
|
8
|
+
|
9
|
+
## 1.0.0.rc1 (2021-02-10)
|
10
|
+
|
11
|
+
### Breaking changes
|
12
|
+
|
13
|
+
* Ruby 1.9.3 - 2.3/Rails 3.2 - 4.2 のサポートを終了 (PR [#39](https://github.com/chocoby/jp_prefecture/pull/39)/[@chocoby](https://github.com/chocoby))
|
14
|
+
|
15
|
+
古い Ruby/Rails のサポートを終了しました。今後も大きな不具合が見つかった場合、可能な限りは対応する予定です。
|
16
|
+
|
17
|
+
サポートするバージョンの範囲は Ruby/Rails のメンテナンスポリシーに則るのがシンプルですが、この Gem では厳しくする必要はないと考えています。
|
18
|
+
Ruby/Rails のメンテナンスポリシーで決められているバージョンは最低限サポートし、実装やテストのメンテナンスが困難になったバージョンからサポートを終了する方針で検討しています。ご意見があればください。
|
19
|
+
|
20
|
+
* 文字列による検索は項目を指定して検索する (Issue [#24](https://github.com/chocoby/jp_prefecture/issues/24), [#27](https://github.com/chocoby/jp_prefecture/issues/27)/PR [#43](https://github.com/chocoby/jp_prefecture/pull/43)/[@chocoby](https://github.com/chocoby))
|
21
|
+
|
22
|
+
`JpPrefecture::Prefecture.find(name: '東')` を実行すると、青森県が取得されていた問題への対応です。これはマッピングのすべての項目を検索していたためです。
|
23
|
+
対応として、`name` を指定した場合は漢字表記、`name_e` は英語表記など、指定した項目のみを検索するように変更しました。詳しい使い方は README を参照してください。
|
24
|
+
以前のように、すべての項目から検索したい場合は `JpPrefecture::Prefecture.find(all_fields: 'string')` を使用してください。
|
25
|
+
|
26
|
+
### Features
|
27
|
+
|
28
|
+
* Ruby 3.0 をサポートに追加 (PR [#42](https://github.com/chocoby/jp_prefecture/pull/42)/[@chocoby](https://github.com/chocoby))
|
29
|
+
* 郵便番号データを更新 (PR [#46](https://github.com/chocoby/jp_prefecture/pull/46)/[@chocoby](https://github.com/chocoby))
|
30
|
+
* `JpPrefecture::Prefecture` クラスに都道府県コードから都道府県インスタンスを作成する `build_by_code` メソッドを追加 (PR [#44](https://github.com/chocoby/jp_prefecture/pull/44)/[@chocoby](https://github.com/chocoby))
|
31
|
+
|
32
|
+
都道府県コードを指定すると、それに対応した都道府県の `JpPrefecture::Prefecture` インスタンスを取得するメソッドを追加しました。
|
33
|
+
`JpPrefecture::Prefecture.build` メソッドは参照している処理がなくなったため、削除しました。
|
34
|
+
|
35
|
+
### Documentation
|
36
|
+
|
37
|
+
* CONTRIBUTING.md を追加 (PR [#41](https://github.com/chocoby/jp_prefecture/pull/41)/[@chocoby](https://github.com/chocoby))
|
38
|
+
|
39
|
+
### Misc
|
40
|
+
|
41
|
+
* RuboCop を導入 (PR [#40](https://github.com/chocoby/jp_prefecture/pull/40)/[@chocoby](https://github.com/chocoby))
|
42
|
+
* Gem に含めるファイルを最低限のものにする (PR [#48](https://github.com/chocoby/jp_prefecture/pull/48)/[@chocoby](https://github.com/chocoby))
|
43
|
+
|
44
|
+
## 0.11.0 (2020-12-18)
|
45
|
+
|
46
|
+
* Rails 6.1 をサポート (PR [#37](https://github.com/chocoby/jp_prefecture/pull/37)/[@chocoby](https://github.com/chocoby))
|
47
|
+
* GitHub Actions でビルドを実行するようにした (PR [#34](https://github.com/chocoby/jp_prefecture/pull/34)/[@chocoby](https://github.com/chocoby))
|
48
|
+
|
49
|
+
## 0.10.0 (2019-08-19)
|
50
|
+
|
51
|
+
* Rails 6.0 をサポート (PR [#33](https://github.com/chocoby/jp_prefecture/pull/33)/[@chocoby](https://github.com/chocoby))
|
52
|
+
|
53
|
+
## 0.9.0 (2017-01-15)
|
54
|
+
|
55
|
+
* Add English Readme (Issue [#21](https://github.com/chocoby/jp_prefecture/issues/21)/PR [#22](https://github.com/chocoby/jp_prefecture/pull/22)/[@PeterTeng](https://github.com/PeterTeng))
|
56
|
+
* 都道府県情報に種類を追加 (PR [#23](https://github.com/chocoby/jp_prefecture/pull/23)/[@gazayas](https://github.com/gazayas))
|
57
|
+
|
58
|
+
## 0.8.1 (2016-03-30)
|
2
59
|
|
3
60
|
* `JpPrefecture::Prefecture.find(name: name)` に `nil` や空文字を渡した時に `nil` を返す (Issue [#18](https://github.com/chocoby/jp_prefecture/issues/18)/PR [#19](https://github.com/chocoby/jp_prefecture/pull/19)/[@k-motoyan](https://github.com/k-motoyan))
|
4
61
|
|
5
|
-
## 0.8.0 (
|
62
|
+
## 0.8.0 (2014-09-07)
|
6
63
|
|
7
64
|
* 都道府県情報に八地方区分情報を追加 (PR [#14](https://github.com/chocoby/jp_prefecture/pull/14)/[@kkosuge](https://github.com/kkosuge))
|
8
65
|
|
9
|
-
## 0.7.0 (
|
66
|
+
## 0.7.0 (2014-06-18)
|
10
67
|
|
11
68
|
* 都道府県名にひらがな、カタカナを追加 (PR [#12](https://github.com/chocoby/jp_prefecture/pull/12)/[@yukihr](https://github.com/yukihr))
|
12
69
|
|
13
|
-
## 0.6.0 (
|
70
|
+
## 0.6.0 (2014-03-10)
|
14
71
|
|
15
72
|
* 都道府県名を前方一致で検索できるようにした (PR [#11](https://github.com/chocoby/jp_prefecture/pull/11)/[@yuuna](https://github.com/yuuna))
|
16
73
|
* 都道府県名の検索ロジックを高速化
|
17
74
|
|
18
|
-
## 0.5.0 (
|
75
|
+
## 0.5.0 (2013-11-30)
|
19
76
|
|
20
77
|
* 郵便番号から都道府県を検索する機能の追加 (PR [#9](https://github.com/chocoby/jp_prefecture/pull/9)/[@fruwe](https://github.com/fruwe))
|
21
78
|
|
22
|
-
## 0.4.0 (
|
79
|
+
## 0.4.0 (2013-07-08)
|
23
80
|
|
24
81
|
* 都道府県のマッピングを変更する機能の追加 (PR [#8](https://github.com/chocoby/jp_prefecture/pull/8)/[@mizoR](https://github.com/mizoR))
|
25
82
|
|
26
|
-
## 0.3.2 (
|
83
|
+
## 0.3.2 (2013-06-12)
|
27
84
|
|
28
85
|
* 文字列を downcase してから都道府県の検索を行うようにした
|
29
86
|
|
30
|
-
## 0.3.1 (
|
87
|
+
## 0.3.1 (2013-06-11)
|
31
88
|
|
32
89
|
* name で渡した文字列が変更されるバグを修正
|
33
90
|
|
34
|
-
## 0.3.0 (
|
91
|
+
## 0.3.0 (2013-06-11)
|
35
92
|
|
36
93
|
* 都道府県名(英語表記含む)から都道府県を検索できるようにした
|
37
94
|
* 都道府県名からの検索と同様の方法で、都道府県コードを検索できるようにした
|
38
95
|
* String 型の都道府県コードに対応
|
39
96
|
|
40
|
-
## 0.2.0 (
|
97
|
+
## 0.2.0 (2013-06-09)
|
41
98
|
|
42
99
|
* 英語表記を追加
|
43
100
|
* Ruby 1.8.7 のサポートを終了
|
44
101
|
|
45
|
-
## 0.1.1 (
|
102
|
+
## 0.1.1 (2013-03-01)
|
46
103
|
|
47
104
|
* モデルで使用する時に、生成するメソッド名を指定できるようにした
|
48
105
|
* Configuration モデル/Model モジュールを廃止
|
49
106
|
* extend による使用を廃止
|
50
107
|
* Travis CI によるテストを行うようにした
|
51
108
|
|
52
|
-
## 0.1.0 (
|
109
|
+
## 0.1.0 (2013-02-17)
|
53
110
|
|
54
111
|
* モデルで使用する時に、対象のカラム名を指定するようにした
|
55
112
|
|
56
|
-
## 0.0.1 (
|
113
|
+
## 0.0.1 (2013-02-14)
|
57
114
|
|
58
115
|
* 都道府県の変換
|
59
116
|
* 簡単な Rails サポート
|
data/LICENSE
CHANGED
@@ -1,22 +1,21 @@
|
|
1
|
-
Copyright (c) 2013 chocoby
|
2
|
-
|
3
1
|
MIT License
|
4
2
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
the
|
3
|
+
Copyright (c) 2020 Kenta Okamoto
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
12
11
|
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
15
14
|
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
OF
|
22
|
-
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# JpPrefecture
|
2
2
|
|
3
|
+
[**English**](README_EN.md)
|
4
|
+
|
3
5
|
[](https://rubygems.org/gems/jp_prefecture)
|
4
|
-
[](https://github.com/chocoby/jp_prefecture)
|
5
7
|
[](https://coveralls.io/r/chocoby/jp_prefecture)
|
6
|
-
[](https://codeclimate.com/github/chocoby/jp_prefecture)
|
7
|
-
[](https://gemnasium.com/chocoby/jp_prefecture)
|
8
8
|
|
9
9
|
https://rubygems.org/gems/jp_prefecture
|
10
10
|
|
@@ -27,21 +27,6 @@ JIS X 0402 で定義されている都道府県コードをベースに、
|
|
27
27
|
|
28
28
|
また、Rails のプラグインとして使用することもできます。
|
29
29
|
|
30
|
-
## インストール
|
31
|
-
|
32
|
-
以下の行を `Gemfile` に記述してから:
|
33
|
-
|
34
|
-
```
|
35
|
-
gem 'jp_prefecture'
|
36
|
-
```
|
37
|
-
|
38
|
-
`bundle` を実行してください。
|
39
|
-
|
40
|
-
または、手動でインストールしてください:
|
41
|
-
|
42
|
-
```
|
43
|
-
$ gem install jp_prefecture
|
44
|
-
```
|
45
30
|
|
46
31
|
## 使い方
|
47
32
|
|
@@ -56,7 +41,7 @@ require 'jp_prefecture'
|
|
56
41
|
都道府県コードを渡すと、都道府県コードから都道府県を検索します:
|
57
42
|
|
58
43
|
```ruby
|
59
|
-
pref = JpPrefecture::Prefecture.find
|
44
|
+
pref = JpPrefecture::Prefecture.find(13)
|
60
45
|
# => #<JpPrefecture::Prefecture:0x007fceb11927d8 @code=13, @name="東京都", @name_e="Tokyo", @name_h="とうきょうと", @name_k="トウキョウト", @zips=[1000000..2080035], @area="関東">
|
61
46
|
pref.code
|
62
47
|
# => 13
|
@@ -70,23 +55,40 @@ pref.name_k
|
|
70
55
|
# => "トウキョウト"
|
71
56
|
pref.area
|
72
57
|
# => "関東"
|
58
|
+
pref.type
|
59
|
+
# => "都"
|
73
60
|
```
|
74
61
|
|
75
62
|
以下のように書くことも可能です:
|
76
63
|
|
77
64
|
```ruby
|
78
|
-
JpPrefecture::Prefecture.find
|
65
|
+
JpPrefecture::Prefecture.find(code: 13)
|
66
|
+
```
|
67
|
+
|
68
|
+
### 都道府県を検索
|
69
|
+
|
70
|
+
前方一致で都道府県を検索します:
|
71
|
+
|
72
|
+
```ruby
|
73
|
+
# 漢字表記
|
74
|
+
JpPrefecture::Prefecture.find(name: "東京都")
|
75
|
+
JpPrefecture::Prefecture.find(name: "東京")
|
76
|
+
|
77
|
+
# 英語表記
|
78
|
+
JpPrefecture::Prefecture.find(name_e: "Tokyo")
|
79
|
+
JpPrefecture::Prefecture.find(name_e: "tokyo")
|
80
|
+
|
81
|
+
# ひらがな表記
|
82
|
+
JpPrefecture::Prefecture.find(name_h: "とうきょうと")
|
83
|
+
|
84
|
+
# カタカナ表記
|
85
|
+
JpPrefecture::Prefecture.find(name_k: "トウキョウト")
|
79
86
|
```
|
80
87
|
|
81
|
-
|
88
|
+
マッピングのすべての項目を検索します (推奨しません):
|
82
89
|
|
83
90
|
```ruby
|
84
|
-
JpPrefecture::Prefecture.find
|
85
|
-
JpPrefecture::Prefecture.find name: "Tokyo"
|
86
|
-
JpPrefecture::Prefecture.find name: "tokyo"
|
87
|
-
JpPrefecture::Prefecture.find name: "トウキョウト"
|
88
|
-
JpPrefecture::Prefecture.find name: "とうきょうと"
|
89
|
-
JpPrefecture::Prefecture.find name: "東京"
|
91
|
+
JpPrefecture::Prefecture.find(all_fields: "東京")
|
90
92
|
```
|
91
93
|
|
92
94
|
### 都道府県の一覧を取得
|
@@ -163,49 +165,60 @@ end
|
|
163
165
|
マッピングデータを指定することができます:
|
164
166
|
|
165
167
|
```ruby
|
166
|
-
custom_mapping_path = "
|
168
|
+
custom_mapping_path = "/path/to/mapping_data.yml"
|
167
169
|
|
168
170
|
JpPrefecture.setup do |config|
|
169
|
-
config.mapping_data = YAML.load_file
|
171
|
+
config.mapping_data = YAML.load_file(custom_mapping_path)
|
170
172
|
end
|
171
173
|
```
|
172
174
|
|
173
175
|
マッピングデータのフォーマットについては [prefecture.yml](https://github.com/chocoby/jp_prefecture/blob/master/data/prefecture.yml) を参考にしてください。
|
174
176
|
|
175
|
-
|
177
|
+
### 郵便番号の情報を変更する
|
176
178
|
|
177
|
-
|
179
|
+
```ruby
|
180
|
+
custom_zip_mapping_path = "/path/to/zip_mapping_data.yml"
|
178
181
|
|
179
|
-
|
182
|
+
JpPrefecture.setup do |config|
|
183
|
+
config.zip_mapping_data = YAML.load_file(custom_zip_mapping_path)
|
184
|
+
end
|
185
|
+
```
|
180
186
|
|
181
|
-
|
187
|
+
データのフォーマットについては [zip.yml](https://github.com/chocoby/jp_prefecture/blob/master/data/zip.yml) を参考にしてください。
|
182
188
|
|
183
|
-
## サポートしているバージョン
|
184
189
|
|
185
|
-
|
186
|
-
* Rails: 3.2 / 4.0 / 4.1 / 4.2
|
190
|
+
## インストール
|
187
191
|
|
188
|
-
|
192
|
+
以下の行を `Gemfile` に記述してから:
|
193
|
+
|
194
|
+
```ruby
|
195
|
+
gem 'jp_prefecture'
|
196
|
+
```
|
189
197
|
|
190
|
-
|
191
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
192
|
-
3. Commit your changes (`git commit -am 'Added some feature'`)
|
193
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
194
|
-
5. Create new Pull Request
|
198
|
+
`bundle` を実行してください。
|
195
199
|
|
196
|
-
|
200
|
+
または、手動でインストールしてください:
|
197
201
|
|
198
202
|
```
|
199
|
-
|
200
|
-
cd jp_prefecture
|
201
|
-
bundle install --path .bundle
|
202
|
-
bundle exec rspec
|
203
|
+
$ gem install jp_prefecture
|
203
204
|
```
|
204
205
|
|
205
|
-
## GitHub
|
206
206
|
|
207
|
-
|
207
|
+
## ドキュメント
|
208
|
+
|
209
|
+
[http://rdoc.info/github/chocoby/jp_prefecture/master/frames/index](http://rdoc.info/github/chocoby/jp_prefecture/master/frames/index)
|
210
|
+
|
211
|
+
## サポートしているバージョン
|
212
|
+
|
213
|
+
* Ruby: 2.4 - 3.0
|
214
|
+
* Rails: 5.0 - 6.1
|
208
215
|
|
209
|
-
|
216
|
+
これより古い Ruby/Rails バージョンを使用する場合は、[`v0.11.0`](https://github.com/chocoby/jp_prefecture/tree/0.x) を利用してください。
|
210
217
|
|
211
|
-
|
218
|
+
## Contributing
|
219
|
+
|
220
|
+
[CONTRIBUTING.md](https://github.com/chocoby/jp_prefecture/blob/master/CONTRIBUTING.md) を確認してください。
|
221
|
+
|
222
|
+
## GitHub
|
223
|
+
|
224
|
+
https://github.com/chocoby/jp_prefecture
|
data/README_EN.md
ADDED
@@ -0,0 +1,227 @@
|
|
1
|
+
# JpPrefecture
|
2
|
+
|
3
|
+
[**Japanese**](README.md)
|
4
|
+
|
5
|
+
[](https://rubygems.org/gems/jp_prefecture)
|
6
|
+
[](https://github.com/chocoby/jp_prefecture)
|
7
|
+
[](https://coveralls.io/r/chocoby/jp_prefecture)
|
8
|
+
|
9
|
+
https://rubygems.org/gems/jp_prefecture
|
10
|
+
|
11
|
+
## Description
|
12
|
+
|
13
|
+
Convert prefecture code to prefecture name in Japan.
|
14
|
+
|
15
|
+
Based on JIS X 0402. Remove 0 when prefecture code start with 0.
|
16
|
+
|
17
|
+
```
|
18
|
+
Hokkaido: 01 -> 1
|
19
|
+
Tokyo: 13 -> 13
|
20
|
+
```
|
21
|
+
|
22
|
+
Reference(Japanese): [Wikipedia: 全国地方公共団体コード](http://ja.wikipedia.org/wiki/%E5%85%A8%E5%9B%BD%E5%9C%B0%E6%96%B9%E5%85%AC%E5%85%B1%E5%9B%A3%E4%BD%93%E3%82%B3%E3%83%BC%E3%83%89#.E9.83.BD.E9.81.93.E5.BA.9C.E7.9C.8C.E3.82.B3.E3.83.BC.E3.83.89)
|
23
|
+
|
24
|
+
You can change prefecture code and prefecture name's mapping data. Please check this [Customize mapping data](#customize-mapping-data)
|
25
|
+
|
26
|
+
Also available as a Rails plugin
|
27
|
+
|
28
|
+
## Usage
|
29
|
+
|
30
|
+
### Requirement
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
require 'jp_prefecture'
|
34
|
+
```
|
35
|
+
|
36
|
+
### Search Prefecture by Code
|
37
|
+
|
38
|
+
Provide prefecture code to search prefecture's data
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
pref = JpPrefecture::Prefecture.find(13)
|
42
|
+
# => #<JpPrefecture::Prefecture:0x007fceb11927d8 @code=13, @name="東京都", @name_e="Tokyo", @name_h="とうきょうと", @name_k="トウキョウト", @zips=[1000000..2080035], @area="関東">
|
43
|
+
pref.code
|
44
|
+
# => 13
|
45
|
+
pref.name
|
46
|
+
# => "東京都"
|
47
|
+
pref.name_e
|
48
|
+
# => "Tokyo"
|
49
|
+
pref.name_h
|
50
|
+
# => "とうきょうと"
|
51
|
+
pref.name_k
|
52
|
+
# => "トウキョウト"
|
53
|
+
pref.area
|
54
|
+
# => "関東"
|
55
|
+
pref.type
|
56
|
+
# => "都"
|
57
|
+
```
|
58
|
+
|
59
|
+
or
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
JpPrefecture::Prefecture.find(code: 13)
|
63
|
+
```
|
64
|
+
|
65
|
+
### Search by Prefecture Name
|
66
|
+
|
67
|
+
Search for a prefecture by forward match.
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
# Kanji
|
71
|
+
JpPrefecture::Prefecture.find(name: "東京都")
|
72
|
+
JpPrefecture::Prefecture.find(name: "東京")
|
73
|
+
|
74
|
+
# English
|
75
|
+
JpPrefecture::Prefecture.find(name_e: "Tokyo")
|
76
|
+
JpPrefecture::Prefecture.find(name_e: "tokyo")
|
77
|
+
|
78
|
+
# Hiragana
|
79
|
+
JpPrefecture::Prefecture.find(name_h: "とうきょうと")
|
80
|
+
|
81
|
+
# Katakana
|
82
|
+
JpPrefecture::Prefecture.find(name_k: "トウキョウト")
|
83
|
+
```
|
84
|
+
|
85
|
+
Search all items in the mapping (not recommended).
|
86
|
+
|
87
|
+
```ruby
|
88
|
+
JpPrefecture::Prefecture.find(all_fields: "東京")
|
89
|
+
```
|
90
|
+
|
91
|
+
### All Prefectures
|
92
|
+
|
93
|
+
```ruby
|
94
|
+
JpPrefecture::Prefecture.all
|
95
|
+
# => [#<JpPrefecture::Prefecture:0x007fceb119a2a8 @code=1, @name="北海道", @name_e="Hokkaido", @name_h="ほっかいどう", @name_k="ホッカイドウ", @zips=[10000..70895, 400000..996509], @area="北海道">, ...]
|
96
|
+
```
|
97
|
+
|
98
|
+
### Usage on Rails (ActiveRecord)
|
99
|
+
|
100
|
+
Include JpPrefecture to Model which `ActiveRecord::Base` inherited.
|
101
|
+
|
102
|
+
app/models/place.rb:
|
103
|
+
|
104
|
+
```ruby
|
105
|
+
class Place < ActiveRecord::Base
|
106
|
+
# prefecture_code:integer
|
107
|
+
|
108
|
+
include JpPrefecture
|
109
|
+
jp_prefecture :prefecture_code
|
110
|
+
end
|
111
|
+
```
|
112
|
+
|
113
|
+
By JpPrefecture included, `prefecture` method will be generated:
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
place = Place.new
|
117
|
+
place.prefecture_code = 13
|
118
|
+
place.prefecture.name_e
|
119
|
+
# => "Tokyo"
|
120
|
+
```
|
121
|
+
|
122
|
+
Customize `prefecture` method name with `method_name` option:
|
123
|
+
|
124
|
+
```ruby
|
125
|
+
# model
|
126
|
+
jp_prefecture :prefecture_code, method_name: :pref
|
127
|
+
|
128
|
+
place = Place.new
|
129
|
+
place.prefecture_code = 13
|
130
|
+
place.pref.name_e
|
131
|
+
# => "Tokyo"
|
132
|
+
```
|
133
|
+
|
134
|
+
### Template usage
|
135
|
+
|
136
|
+
Use `collection_select` to generate selector in view:
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
# Selector prefecture name in English
|
140
|
+
f.collection_select :prefecture_code, JpPrefecture::Prefecture.all, :code, :name_e
|
141
|
+
|
142
|
+
# Selector prefecture name in Japanese
|
143
|
+
f.collection_select :prefecture_code, JpPrefecture::Prefecture.all, :code, :name
|
144
|
+
```
|
145
|
+
|
146
|
+
### Migration
|
147
|
+
|
148
|
+
Set `prefecture_code` column type to `integer` or `string`.
|
149
|
+
|
150
|
+
Example:
|
151
|
+
|
152
|
+
```ruby
|
153
|
+
class AddPrefectureCodeToPlaces < ActiveRecord::Migration
|
154
|
+
def change
|
155
|
+
add_column :places, :prefecture_code, :integer
|
156
|
+
end
|
157
|
+
end
|
158
|
+
```
|
159
|
+
|
160
|
+
### Customize Mapping Data
|
161
|
+
|
162
|
+
Customize mapping data with `mapping_data`.
|
163
|
+
|
164
|
+
```ruby
|
165
|
+
custom_mapping_path = "/path/to/mapping_data.yml"
|
166
|
+
|
167
|
+
JpPrefecture.setup do |config|
|
168
|
+
config.mapping_data = YAML.load_file(custom_mapping_path)
|
169
|
+
end
|
170
|
+
```
|
171
|
+
|
172
|
+
Check out [prefecture.yml](https://github.com/chocoby/jp_prefecture/blob/master/data/prefecture.yml) for data format.
|
173
|
+
|
174
|
+
### Customize Zip Code Data
|
175
|
+
|
176
|
+
Customize zip code data with `zip_mapping_data`.
|
177
|
+
|
178
|
+
```ruby
|
179
|
+
custom_zip_mapping_path = "/path/to/zip_mapping_data.yml"
|
180
|
+
|
181
|
+
JpPrefecture.setup do |config|
|
182
|
+
config.zip_mapping_data = YAML.load_file(custom_zip_mapping_path)
|
183
|
+
end
|
184
|
+
```
|
185
|
+
|
186
|
+
Check out [zip.yml](https://github.com/chocoby/jp_prefecture/blob/master/data/zip.yml) for data format.
|
187
|
+
|
188
|
+
|
189
|
+
## Installation
|
190
|
+
|
191
|
+
Add this line in Gemfile.
|
192
|
+
|
193
|
+
```ruby
|
194
|
+
gem 'jp_prefecture'
|
195
|
+
```
|
196
|
+
|
197
|
+
Run
|
198
|
+
|
199
|
+
```
|
200
|
+
$ bundle
|
201
|
+
```
|
202
|
+
|
203
|
+
Or install gem with `gem install`
|
204
|
+
|
205
|
+
```
|
206
|
+
$ gem install jp_prefecture
|
207
|
+
```
|
208
|
+
|
209
|
+
|
210
|
+
## Documentation
|
211
|
+
|
212
|
+
[http://rdoc.info/github/chocoby/jp_prefecture/master/frames/index](http://rdoc.info/github/chocoby/jp_prefecture/master/frames/index)
|
213
|
+
|
214
|
+
## Supported versions
|
215
|
+
|
216
|
+
* Ruby: 2.4 - 3.0
|
217
|
+
* Rails: 5.0 - 6.1
|
218
|
+
|
219
|
+
If you are using an older Ruby/Rails version, please use [`v0.11.0`](https://github.com/chocoby/jp_prefecture/tree/0.x).
|
220
|
+
|
221
|
+
## Contributing
|
222
|
+
|
223
|
+
See [CONTRIBUTING.md](https://github.com/chocoby/jp_prefecture/blob/master/CONTRIBUTING.md).
|
224
|
+
|
225
|
+
## GitHub
|
226
|
+
|
227
|
+
https://github.com/chocoby/jp_prefecture
|