jp_prefecture 0.11.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +65 -16
- data/LICENSE +21 -0
- data/README.md +53 -41
- data/README_EN.md +55 -41
- data/data/prefecture.yml +47 -0
- data/data/zip.yml +13 -4
- 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/finder.rb +71 -0
- data/lib/jp_prefecture/prefecture.rb +76 -105
- data/lib/jp_prefecture/version.rb +3 -1
- data/lib/jp_prefecture/zip_mapping.rb +6 -6
- data/lib/jp_prefecture.rb +6 -5
- metadata +72 -47
- data/.github/workflows/build.yml +0 -78
- data/.gitignore +0 -20
- data/.rspec +0 -2
- data/.yardopts +0 -2
- data/Appraisals +0 -46
- data/Gemfile +0 -3
- data/MIT-LICENSE +0 -22
- data/Rakefile +0 -64
- data/gemfiles/rails32.gemfile +0 -8
- data/gemfiles/rails40.gemfile +0 -8
- data/gemfiles/rails41.gemfile +0 -8
- data/gemfiles/rails42.gemfile +0 -8
- data/gemfiles/rails50.gemfile +0 -8
- data/gemfiles/rails51.gemfile +0 -8
- data/gemfiles/rails52.gemfile +0 -8
- data/gemfiles/rails60.gemfile +0 -7
- data/gemfiles/rails61.gemfile +0 -7
- data/jp_prefecture.gemspec +0 -26
- 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 -175
- data/spec/spec_helper.rb +0 -41
- data/spec/zip_mapping_spec.rb +0 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e56e5934f4a9edbc985a3981f34158532b196b931e48a87f880dca4e110058a
|
4
|
+
data.tar.gz: 77c5afce644db03f513772371addec79d580aa9871a8c2dd4a69179ff2ddeac2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d029ccc7550e3c0196004e14a2ecab7b9a4835497689ca76ad654299359b637f34848822869724d9e55b82de410317e6063a77101b0c664f625a6fa59cba5bcc
|
7
|
+
data.tar.gz: da4f9b9c14d16f3ac00e34daf3cbc9a2cc5a7016851450d8441344c6de12515df14bbde206145bdf004aaff25e4b72dbc910f904ce09481bcfe085ce90e6413d
|
data/CHANGELOG.md
CHANGED
@@ -1,75 +1,124 @@
|
|
1
1
|
## Unreleased
|
2
2
|
|
3
|
-
##
|
3
|
+
## 1.1.0 (2022-03-17)
|
4
|
+
|
5
|
+
### Features
|
6
|
+
|
7
|
+
* 都道府県情報にローマ字表記を追加 (PR [#57](https://github.com/chocoby/jp_prefecture/pull/57)/[@sondh5](https://github.com/sondh5))
|
8
|
+
* Ruby 3.1 をサポートに追加 (PR [#54](https://github.com/chocoby/jp_prefecture/pull/54)/[@chocoby](https://github.com/chocoby))
|
9
|
+
* Rails 7.0 をサポート (PR [#55](https://github.com/chocoby/jp_prefecture/pull/55)/[@chocoby](https://github.com/chocoby))
|
10
|
+
|
11
|
+
## 1.0.0 (2021-02-24)
|
12
|
+
|
13
|
+
### Misc
|
14
|
+
|
15
|
+
* 毎週月曜日の 09:00 (JST) にテストを実行する (PR [#52](https://github.com/chocoby/jp_prefecture/pull/52)/[@chocoby](https://github.com/chocoby))
|
16
|
+
|
17
|
+
## 1.0.0.rc1 (2021-02-10)
|
18
|
+
|
19
|
+
### Breaking changes
|
20
|
+
|
21
|
+
* 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))
|
22
|
+
|
23
|
+
古い Ruby/Rails のサポートを終了しました。今後も大きな不具合が見つかった場合、可能な限りは対応する予定です。
|
24
|
+
|
25
|
+
サポートするバージョンの範囲は Ruby/Rails のメンテナンスポリシーに則るのがシンプルですが、この Gem では厳しくする必要はないと考えています。
|
26
|
+
Ruby/Rails のメンテナンスポリシーで決められているバージョンは最低限サポートし、実装やテストのメンテナンスが困難になったバージョンからサポートを終了する方針で検討しています。ご意見があればください。
|
27
|
+
|
28
|
+
* 文字列による検索は項目を指定して検索する (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))
|
29
|
+
|
30
|
+
`JpPrefecture::Prefecture.find(name: '東')` を実行すると、青森県が取得されていた問題への対応です。これはマッピングのすべての項目を検索していたためです。
|
31
|
+
対応として、`name` を指定した場合は漢字表記、`name_e` は英語表記など、指定した項目のみを検索するように変更しました。詳しい使い方は README を参照してください。
|
32
|
+
以前のように、すべての項目から検索したい場合は `JpPrefecture::Prefecture.find(all_fields: 'string')` を使用してください。
|
33
|
+
|
34
|
+
### Features
|
35
|
+
|
36
|
+
* Ruby 3.0 をサポートに追加 (PR [#42](https://github.com/chocoby/jp_prefecture/pull/42)/[@chocoby](https://github.com/chocoby))
|
37
|
+
* 郵便番号データを更新 (PR [#46](https://github.com/chocoby/jp_prefecture/pull/46)/[@chocoby](https://github.com/chocoby))
|
38
|
+
* `JpPrefecture::Prefecture` クラスに都道府県コードから都道府県インスタンスを作成する `build_by_code` メソッドを追加 (PR [#44](https://github.com/chocoby/jp_prefecture/pull/44)/[@chocoby](https://github.com/chocoby))
|
39
|
+
|
40
|
+
都道府県コードを指定すると、それに対応した都道府県の `JpPrefecture::Prefecture` インスタンスを取得するメソッドを追加しました。
|
41
|
+
`JpPrefecture::Prefecture.build` メソッドは参照している処理がなくなったため、削除しました。
|
42
|
+
|
43
|
+
### Documentation
|
44
|
+
|
45
|
+
* CONTRIBUTING.md を追加 (PR [#41](https://github.com/chocoby/jp_prefecture/pull/41)/[@chocoby](https://github.com/chocoby))
|
46
|
+
|
47
|
+
### Misc
|
48
|
+
|
49
|
+
* RuboCop を導入 (PR [#40](https://github.com/chocoby/jp_prefecture/pull/40)/[@chocoby](https://github.com/chocoby))
|
50
|
+
* Gem に含めるファイルを最低限のものにする (PR [#48](https://github.com/chocoby/jp_prefecture/pull/48)/[@chocoby](https://github.com/chocoby))
|
51
|
+
|
52
|
+
## 0.11.0 (2020-12-18)
|
4
53
|
|
5
54
|
* Rails 6.1 をサポート (PR [#37](https://github.com/chocoby/jp_prefecture/pull/37)/[@chocoby](https://github.com/chocoby))
|
6
55
|
* GitHub Actions でビルドを実行するようにした (PR [#34](https://github.com/chocoby/jp_prefecture/pull/34)/[@chocoby](https://github.com/chocoby))
|
7
56
|
|
8
|
-
## 0.10.0 (
|
57
|
+
## 0.10.0 (2019-08-19)
|
9
58
|
|
10
59
|
* Rails 6.0 をサポート (PR [#33](https://github.com/chocoby/jp_prefecture/pull/33)/[@chocoby](https://github.com/chocoby))
|
11
60
|
|
12
|
-
## 0.9.0 (
|
61
|
+
## 0.9.0 (2017-01-15)
|
13
62
|
|
14
63
|
* 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))
|
15
64
|
* 都道府県情報に種類を追加 (PR [#23](https://github.com/chocoby/jp_prefecture/pull/23)/[@gazayas](https://github.com/gazayas))
|
16
65
|
|
17
|
-
## 0.8.1 (
|
66
|
+
## 0.8.1 (2016-03-30)
|
18
67
|
|
19
68
|
* `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))
|
20
69
|
|
21
|
-
## 0.8.0 (
|
70
|
+
## 0.8.0 (2014-09-07)
|
22
71
|
|
23
72
|
* 都道府県情報に八地方区分情報を追加 (PR [#14](https://github.com/chocoby/jp_prefecture/pull/14)/[@kkosuge](https://github.com/kkosuge))
|
24
73
|
|
25
|
-
## 0.7.0 (
|
74
|
+
## 0.7.0 (2014-06-18)
|
26
75
|
|
27
76
|
* 都道府県名にひらがな、カタカナを追加 (PR [#12](https://github.com/chocoby/jp_prefecture/pull/12)/[@yukihr](https://github.com/yukihr))
|
28
77
|
|
29
|
-
## 0.6.0 (
|
78
|
+
## 0.6.0 (2014-03-10)
|
30
79
|
|
31
80
|
* 都道府県名を前方一致で検索できるようにした (PR [#11](https://github.com/chocoby/jp_prefecture/pull/11)/[@yuuna](https://github.com/yuuna))
|
32
81
|
* 都道府県名の検索ロジックを高速化
|
33
82
|
|
34
|
-
## 0.5.0 (
|
83
|
+
## 0.5.0 (2013-11-30)
|
35
84
|
|
36
85
|
* 郵便番号から都道府県を検索する機能の追加 (PR [#9](https://github.com/chocoby/jp_prefecture/pull/9)/[@fruwe](https://github.com/fruwe))
|
37
86
|
|
38
|
-
## 0.4.0 (
|
87
|
+
## 0.4.0 (2013-07-08)
|
39
88
|
|
40
89
|
* 都道府県のマッピングを変更する機能の追加 (PR [#8](https://github.com/chocoby/jp_prefecture/pull/8)/[@mizoR](https://github.com/mizoR))
|
41
90
|
|
42
|
-
## 0.3.2 (
|
91
|
+
## 0.3.2 (2013-06-12)
|
43
92
|
|
44
93
|
* 文字列を downcase してから都道府県の検索を行うようにした
|
45
94
|
|
46
|
-
## 0.3.1 (
|
95
|
+
## 0.3.1 (2013-06-11)
|
47
96
|
|
48
97
|
* name で渡した文字列が変更されるバグを修正
|
49
98
|
|
50
|
-
## 0.3.0 (
|
99
|
+
## 0.3.0 (2013-06-11)
|
51
100
|
|
52
101
|
* 都道府県名(英語表記含む)から都道府県を検索できるようにした
|
53
102
|
* 都道府県名からの検索と同様の方法で、都道府県コードを検索できるようにした
|
54
103
|
* String 型の都道府県コードに対応
|
55
104
|
|
56
|
-
## 0.2.0 (
|
105
|
+
## 0.2.0 (2013-06-09)
|
57
106
|
|
58
107
|
* 英語表記を追加
|
59
108
|
* Ruby 1.8.7 のサポートを終了
|
60
109
|
|
61
|
-
## 0.1.1 (
|
110
|
+
## 0.1.1 (2013-03-01)
|
62
111
|
|
63
112
|
* モデルで使用する時に、生成するメソッド名を指定できるようにした
|
64
113
|
* Configuration モデル/Model モジュールを廃止
|
65
114
|
* extend による使用を廃止
|
66
115
|
* Travis CI によるテストを行うようにした
|
67
116
|
|
68
|
-
## 0.1.0 (
|
117
|
+
## 0.1.0 (2013-02-17)
|
69
118
|
|
70
119
|
* モデルで使用する時に、対象のカラム名を指定するようにした
|
71
120
|
|
72
|
-
## 0.0.1 (
|
121
|
+
## 0.0.1 (2013-02-14)
|
73
122
|
|
74
123
|
* 都道府県の変換
|
75
124
|
* 簡単な Rails サポート
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
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:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
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
@@ -41,14 +41,16 @@ require 'jp_prefecture'
|
|
41
41
|
都道府県コードを渡すと、都道府県コードから都道府県を検索します:
|
42
42
|
|
43
43
|
```ruby
|
44
|
-
pref = JpPrefecture::Prefecture.find
|
45
|
-
# => #<JpPrefecture::Prefecture:
|
44
|
+
pref = JpPrefecture::Prefecture.find(13)
|
45
|
+
# => #<JpPrefecture::Prefecture:0x00000001126b6558 @area="関東", @code=13, @name="東京都", @name_e="Tokyo", @name_h="とうきょうと", @name_k="トウキョウト", @name_r="Tōkyō", @type="都", @zips=[1000000..2080035]>
|
46
46
|
pref.code
|
47
47
|
# => 13
|
48
48
|
pref.name
|
49
49
|
# => "東京都"
|
50
50
|
pref.name_e
|
51
51
|
# => "Tokyo"
|
52
|
+
pref.name_r
|
53
|
+
# => "Tōkyō"
|
52
54
|
pref.name_h
|
53
55
|
# => "とうきょうと"
|
54
56
|
pref.name_k
|
@@ -62,25 +64,44 @@ pref.type
|
|
62
64
|
以下のように書くことも可能です:
|
63
65
|
|
64
66
|
```ruby
|
65
|
-
JpPrefecture::Prefecture.find
|
67
|
+
JpPrefecture::Prefecture.find(code: 13)
|
66
68
|
```
|
67
69
|
|
68
|
-
###
|
70
|
+
### 都道府県を検索
|
71
|
+
|
72
|
+
前方一致で都道府県を検索します:
|
69
73
|
|
70
74
|
```ruby
|
71
|
-
|
72
|
-
JpPrefecture::Prefecture.find
|
73
|
-
JpPrefecture::Prefecture.find
|
74
|
-
|
75
|
-
|
76
|
-
JpPrefecture::Prefecture.find
|
75
|
+
# 漢字表記
|
76
|
+
JpPrefecture::Prefecture.find(name: "東京都")
|
77
|
+
JpPrefecture::Prefecture.find(name: "東京")
|
78
|
+
|
79
|
+
# 英語表記
|
80
|
+
JpPrefecture::Prefecture.find(name_e: "Tokyo")
|
81
|
+
JpPrefecture::Prefecture.find(name_e: "tokyo")
|
82
|
+
|
83
|
+
# ローマ字表記
|
84
|
+
JpPrefecture::Prefecture.find(name_r: "Tōkyō")
|
85
|
+
JpPrefecture::Prefecture.find(name_r: "tōkyō")
|
86
|
+
|
87
|
+
# ひらがな表記
|
88
|
+
JpPrefecture::Prefecture.find(name_h: "とうきょうと")
|
89
|
+
|
90
|
+
# カタカナ表記
|
91
|
+
JpPrefecture::Prefecture.find(name_k: "トウキョウト")
|
92
|
+
```
|
93
|
+
|
94
|
+
マッピングのすべての項目を検索します (推奨しません):
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
JpPrefecture::Prefecture.find(all_fields: "東京")
|
77
98
|
```
|
78
99
|
|
79
100
|
### 都道府県の一覧を取得
|
80
101
|
|
81
102
|
```ruby
|
82
103
|
JpPrefecture::Prefecture.all
|
83
|
-
# => [#<JpPrefecture::Prefecture:
|
104
|
+
# => [#<JpPrefecture::Prefecture:0x0000000112555ab0 @area="北海道", @code=1, @name="北海道", @name_e="Hokkaido", @name_h="ほっかいどう", @name_k="ホッカイドウ", @name_r="Hokkaidō", @type="道", @zips=[10000..70895, 400000..996509]>, ...]
|
84
105
|
```
|
85
106
|
|
86
107
|
### Rails (ActiveRecord) で使用する
|
@@ -150,21 +171,33 @@ end
|
|
150
171
|
マッピングデータを指定することができます:
|
151
172
|
|
152
173
|
```ruby
|
153
|
-
custom_mapping_path = "
|
174
|
+
custom_mapping_path = "/path/to/mapping_data.yml"
|
154
175
|
|
155
176
|
JpPrefecture.setup do |config|
|
156
|
-
config.mapping_data = YAML.load_file
|
177
|
+
config.mapping_data = YAML.load_file(custom_mapping_path)
|
157
178
|
end
|
158
179
|
```
|
159
180
|
|
160
|
-
マッピングデータのフォーマットについては [prefecture.yml](https://github.com/chocoby/jp_prefecture/blob/
|
181
|
+
マッピングデータのフォーマットについては [prefecture.yml](https://github.com/chocoby/jp_prefecture/blob/main/data/prefecture.yml) を参考にしてください。
|
182
|
+
|
183
|
+
### 郵便番号の情報を変更する
|
184
|
+
|
185
|
+
```ruby
|
186
|
+
custom_zip_mapping_path = "/path/to/zip_mapping_data.yml"
|
187
|
+
|
188
|
+
JpPrefecture.setup do |config|
|
189
|
+
config.zip_mapping_data = YAML.load_file(custom_zip_mapping_path)
|
190
|
+
end
|
191
|
+
```
|
192
|
+
|
193
|
+
データのフォーマットについては [zip.yml](https://github.com/chocoby/jp_prefecture/blob/main/data/zip.yml) を参考にしてください。
|
161
194
|
|
162
195
|
|
163
196
|
## インストール
|
164
197
|
|
165
198
|
以下の行を `Gemfile` に記述してから:
|
166
199
|
|
167
|
-
```
|
200
|
+
```ruby
|
168
201
|
gem 'jp_prefecture'
|
169
202
|
```
|
170
203
|
|
@@ -179,39 +212,18 @@ $ gem install jp_prefecture
|
|
179
212
|
|
180
213
|
## ドキュメント
|
181
214
|
|
182
|
-
[http://rdoc.info/github/chocoby/jp_prefecture/
|
215
|
+
[http://rdoc.info/github/chocoby/jp_prefecture/main/frames/index](http://rdoc.info/github/chocoby/jp_prefecture/main/frames/index)
|
183
216
|
|
184
217
|
## サポートしているバージョン
|
185
218
|
|
186
|
-
* Ruby:
|
187
|
-
* Rails:
|
219
|
+
* Ruby: 2.4 - 3.1
|
220
|
+
* Rails: 5.0 - 7.0
|
188
221
|
|
222
|
+
これより古い Ruby/Rails バージョンを使用する場合は、[`v0.11.0`](https://github.com/chocoby/jp_prefecture/tree/0.x) を利用してください。
|
189
223
|
|
190
224
|
## Contributing
|
191
225
|
|
192
|
-
|
193
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
194
|
-
3. Commit your changes (`git commit -am 'Added some feature'`)
|
195
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
196
|
-
5. Create new Pull Request
|
197
|
-
|
198
|
-
|
199
|
-
## テスト
|
200
|
-
|
201
|
-
```
|
202
|
-
git clone https://github.com/chocoby/jp_prefecture.git
|
203
|
-
cd jp_prefecture
|
204
|
-
bundle install
|
205
|
-
bundle exec rspec
|
206
|
-
```
|
207
|
-
|
208
|
-
複数バージョンの Active Record でテストを実行:
|
209
|
-
|
210
|
-
```
|
211
|
-
bundle exec appraisal install
|
212
|
-
bundle exec appraisal rspec
|
213
|
-
```
|
214
|
-
|
226
|
+
[CONTRIBUTING.md](https://github.com/chocoby/jp_prefecture/blob/main/CONTRIBUTING.md) を確認してください。
|
215
227
|
|
216
228
|
## GitHub
|
217
229
|
|
data/README_EN.md
CHANGED
@@ -38,14 +38,16 @@ require 'jp_prefecture'
|
|
38
38
|
Provide prefecture code to search prefecture's data
|
39
39
|
|
40
40
|
```ruby
|
41
|
-
pref = JpPrefecture::Prefecture.find
|
42
|
-
# => #<JpPrefecture::Prefecture:
|
41
|
+
pref = JpPrefecture::Prefecture.find(13)
|
42
|
+
# => #<JpPrefecture::Prefecture:0x00000001126b6558 @area="関東", @code=13, @name="東京都", @name_e="Tokyo", @name_h="とうきょうと", @name_k="トウキョウト", @name_r="Tōkyō", @type="都", @zips=[1000000..2080035]>
|
43
43
|
pref.code
|
44
44
|
# => 13
|
45
45
|
pref.name
|
46
46
|
# => "東京都"
|
47
47
|
pref.name_e
|
48
48
|
# => "Tokyo"
|
49
|
+
pref.name_r
|
50
|
+
# => "Tōkyō"
|
49
51
|
pref.name_h
|
50
52
|
# => "とうきょうと"
|
51
53
|
pref.name_k
|
@@ -59,25 +61,44 @@ pref.type
|
|
59
61
|
or
|
60
62
|
|
61
63
|
```ruby
|
62
|
-
JpPrefecture::Prefecture.find
|
64
|
+
JpPrefecture::Prefecture.find(code: 13)
|
63
65
|
```
|
64
66
|
|
65
67
|
### Search by Prefecture Name
|
66
68
|
|
69
|
+
Search for a prefecture by forward match.
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
# Kanji
|
73
|
+
JpPrefecture::Prefecture.find(name: "東京都")
|
74
|
+
JpPrefecture::Prefecture.find(name: "東京")
|
75
|
+
|
76
|
+
# English
|
77
|
+
JpPrefecture::Prefecture.find(name_e: "Tokyo")
|
78
|
+
JpPrefecture::Prefecture.find(name_e: "tokyo")
|
79
|
+
|
80
|
+
# Romaji
|
81
|
+
JpPrefecture::Prefecture.find(name_r: "Tōkyō")
|
82
|
+
JpPrefecture::Prefecture.find(name_r: "tōkyō")
|
83
|
+
|
84
|
+
# Hiragana
|
85
|
+
JpPrefecture::Prefecture.find(name_h: "とうきょうと")
|
86
|
+
|
87
|
+
# Katakana
|
88
|
+
JpPrefecture::Prefecture.find(name_k: "トウキョウト")
|
89
|
+
```
|
90
|
+
|
91
|
+
Search all items in the mapping (not recommended).
|
92
|
+
|
67
93
|
```ruby
|
68
|
-
JpPrefecture::Prefecture.find
|
69
|
-
JpPrefecture::Prefecture.find name: "Tokyo"
|
70
|
-
JpPrefecture::Prefecture.find name: "tokyo"
|
71
|
-
JpPrefecture::Prefecture.find name: "トウキョウト"
|
72
|
-
JpPrefecture::Prefecture.find name: "とうきょうと"
|
73
|
-
JpPrefecture::Prefecture.find name: "東京"
|
94
|
+
JpPrefecture::Prefecture.find(all_fields: "東京")
|
74
95
|
```
|
75
96
|
|
76
97
|
### All Prefectures
|
77
98
|
|
78
99
|
```ruby
|
79
100
|
JpPrefecture::Prefecture.all
|
80
|
-
# => [#<JpPrefecture::Prefecture:
|
101
|
+
# => [#<JpPrefecture::Prefecture:0x0000000112555ab0 @area="北海道", @code=1, @name="北海道", @name_e="Hokkaido", @name_h="ほっかいどう", @name_k="ホッカイドウ", @name_r="Hokkaidō", @type="道", @zips=[10000..70895, 400000..996509]>, ...]
|
81
102
|
```
|
82
103
|
|
83
104
|
### Usage on Rails (ActiveRecord)
|
@@ -144,17 +165,31 @@ end
|
|
144
165
|
|
145
166
|
### Customize Mapping Data
|
146
167
|
|
147
|
-
Customize mapping data with `
|
168
|
+
Customize mapping data with `mapping_data`.
|
169
|
+
|
170
|
+
```ruby
|
171
|
+
custom_mapping_path = "/path/to/mapping_data.yml"
|
172
|
+
|
173
|
+
JpPrefecture.setup do |config|
|
174
|
+
config.mapping_data = YAML.load_file(custom_mapping_path)
|
175
|
+
end
|
176
|
+
```
|
177
|
+
|
178
|
+
Check out [prefecture.yml](https://github.com/chocoby/jp_prefecture/blob/main/data/prefecture.yml) for data format.
|
179
|
+
|
180
|
+
### Customize Zip Code Data
|
181
|
+
|
182
|
+
Customize zip code data with `zip_mapping_data`.
|
148
183
|
|
149
184
|
```ruby
|
150
|
-
|
185
|
+
custom_zip_mapping_path = "/path/to/zip_mapping_data.yml"
|
151
186
|
|
152
187
|
JpPrefecture.setup do |config|
|
153
|
-
config.
|
188
|
+
config.zip_mapping_data = YAML.load_file(custom_zip_mapping_path)
|
154
189
|
end
|
155
190
|
```
|
156
191
|
|
157
|
-
Check out [
|
192
|
+
Check out [zip.yml](https://github.com/chocoby/jp_prefecture/blob/main/data/zip.yml) for data format.
|
158
193
|
|
159
194
|
|
160
195
|
## Installation
|
@@ -180,39 +215,18 @@ $ gem install jp_prefecture
|
|
180
215
|
|
181
216
|
## Documentation
|
182
217
|
|
183
|
-
[http://rdoc.info/github/chocoby/jp_prefecture/
|
218
|
+
[http://rdoc.info/github/chocoby/jp_prefecture/main/frames/index](http://rdoc.info/github/chocoby/jp_prefecture/main/frames/index)
|
184
219
|
|
185
|
-
##
|
220
|
+
## Supported versions
|
186
221
|
|
187
|
-
* Ruby:
|
188
|
-
* Rails:
|
222
|
+
* Ruby: 2.4 - 3.1
|
223
|
+
* Rails: 5.0 - 7.0
|
189
224
|
|
225
|
+
If you are using an older Ruby/Rails version, please use [`v0.11.0`](https://github.com/chocoby/jp_prefecture/tree/0.x).
|
190
226
|
|
191
227
|
## Contributing
|
192
228
|
|
193
|
-
|
194
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
195
|
-
3. Commit your changes (`git commit -am 'Added some feature'`)
|
196
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
197
|
-
5. Create new Pull Request
|
198
|
-
|
199
|
-
|
200
|
-
## Test
|
201
|
-
|
202
|
-
```
|
203
|
-
git clone https://github.com/chocoby/jp_prefecture.git
|
204
|
-
cd jp_prefecture
|
205
|
-
bundle install
|
206
|
-
bundle exec rspec
|
207
|
-
```
|
208
|
-
|
209
|
-
Run test in multiple `ActiveRecord` versions
|
210
|
-
|
211
|
-
```
|
212
|
-
bundle exec appraisal install
|
213
|
-
bundle exec appraisal rspec
|
214
|
-
```
|
215
|
-
|
229
|
+
See [CONTRIBUTING.md](https://github.com/chocoby/jp_prefecture/blob/main/CONTRIBUTING.md).
|
216
230
|
|
217
231
|
## GitHub
|
218
232
|
|