jp_prefecture 0.8.0 → 1.0.0.rc1

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