jp_prefecture 0.7.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/build.yml +78 -0
- data/.gitignore +2 -0
- data/.rspec +1 -1
- data/Appraisals +46 -0
- data/CHANGELOG.md +24 -0
- data/{LICENSE → MIT-LICENSE} +0 -0
- data/README.md +53 -44
- data/README_EN.md +219 -0
- data/Rakefile +1 -11
- data/data/prefecture.yml +47 -0
- data/data/zip.yml +1 -1
- data/gemfiles/rails32.gemfile +8 -0
- data/gemfiles/rails40.gemfile +8 -0
- data/gemfiles/rails41.gemfile +8 -0
- data/gemfiles/rails42.gemfile +8 -0
- data/gemfiles/rails50.gemfile +8 -0
- data/gemfiles/rails51.gemfile +8 -0
- data/gemfiles/rails52.gemfile +8 -0
- data/gemfiles/rails60.gemfile +7 -0
- data/gemfiles/rails61.gemfile +7 -0
- data/jp_prefecture.gemspec +13 -9
- data/lib/jp_prefecture/prefecture.rb +15 -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 +48 -20
- data/spec/spec_helper.rb +14 -3
- data/spec/zip_mapping_spec.rb +1 -1
- metadata +69 -16
- data/.travis.yml +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c16ea4e0cdab390ac0f2e7ce37db364d1e9d7dbb7c9cb1ccdb80aa9dc0da4e62
|
4
|
+
data.tar.gz: 566e0820a0aef1caa58dc22ef002a72f44f9b96f1457448ea9721c96717cf076
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 148c89e504aa745015e8eeaed0460be88bc4d23094a98a248d739cb67bceeeaaa5c971cd74d902565b4d8c2c6b636066479c725936e7454b30cb8b0cff81b2f2
|
7
|
+
data.tar.gz: a9408dcea7c0ec9725719c510b594c21d14bf85eb74f57c9dfbc252dda724163133c07dd43aee44df2907f4c01e944d57261fedca489ecb825ff1c9a40edf851
|
@@ -0,0 +1,78 @@
|
|
1
|
+
name: Build
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- master
|
7
|
+
pull_request:
|
8
|
+
types: [opened, synchronize, reopened]
|
9
|
+
|
10
|
+
jobs:
|
11
|
+
matrix:
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
|
14
|
+
strategy:
|
15
|
+
matrix:
|
16
|
+
ruby:
|
17
|
+
- 2.4
|
18
|
+
- 2.5
|
19
|
+
- 2.6
|
20
|
+
- 2.7
|
21
|
+
gemfile:
|
22
|
+
- rails42.gemfile
|
23
|
+
- rails50.gemfile
|
24
|
+
- rails51.gemfile
|
25
|
+
- rails52.gemfile
|
26
|
+
- rails60.gemfile
|
27
|
+
- rails61.gemfile
|
28
|
+
exclude:
|
29
|
+
- ruby: 2.4
|
30
|
+
gemfile: rails60.gemfile
|
31
|
+
- ruby: 2.4
|
32
|
+
gemfile: rails61.gemfile
|
33
|
+
- ruby: 2.5
|
34
|
+
gemfile: rails60.gemfile
|
35
|
+
- ruby: 2.5
|
36
|
+
gemfile: rails61.gemfile
|
37
|
+
- ruby: 2.7
|
38
|
+
gemfile: rails42.gemfile
|
39
|
+
|
40
|
+
env:
|
41
|
+
CI: true
|
42
|
+
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
|
43
|
+
BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}
|
44
|
+
|
45
|
+
steps:
|
46
|
+
- uses: actions/checkout@v1
|
47
|
+
|
48
|
+
- name: Setup System
|
49
|
+
run: |
|
50
|
+
sudo apt-get update
|
51
|
+
sudo apt-get install libsqlite3-dev
|
52
|
+
|
53
|
+
- name: Set up Ruby ${{ matrix.ruby }}
|
54
|
+
uses: eregon/use-ruby-action@master
|
55
|
+
with:
|
56
|
+
ruby-version: ${{ matrix.ruby }}
|
57
|
+
|
58
|
+
- name: Build
|
59
|
+
run: |
|
60
|
+
gem install bundler
|
61
|
+
bundle install --jobs 4 --retry 3
|
62
|
+
|
63
|
+
- name: Test
|
64
|
+
run: |
|
65
|
+
bundle exec rspec
|
66
|
+
|
67
|
+
- name: Coveralls Parallel
|
68
|
+
uses: coverallsapp/github-action@master
|
69
|
+
with:
|
70
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
71
|
+
parallel: true
|
72
|
+
path-to-lcov: ./coverage/lcov.info
|
73
|
+
|
74
|
+
- name: Coveralls Finished
|
75
|
+
uses: coverallsapp/github-action@master
|
76
|
+
with:
|
77
|
+
github-token: ${{ secrets.GITHUB_TOKEN }}
|
78
|
+
parallel-finished: true
|
data/.gitignore
CHANGED
data/.rspec
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
--
|
1
|
+
--color
|
2
2
|
--format documentation
|
data/Appraisals
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
appraise 'rails32' do
|
2
|
+
gem 'activerecord', '~> 3.2.0'
|
3
|
+
gem 'sqlite3', '< 1.4'
|
4
|
+
end
|
5
|
+
|
6
|
+
appraise 'rails40' do
|
7
|
+
gem 'activerecord', '~> 4.0.0'
|
8
|
+
gem 'sqlite3', '< 1.4'
|
9
|
+
end
|
10
|
+
|
11
|
+
appraise 'rails41' do
|
12
|
+
gem 'activerecord', '~> 4.1.0'
|
13
|
+
gem 'sqlite3', '< 1.4'
|
14
|
+
end
|
15
|
+
|
16
|
+
appraise 'rails42' do
|
17
|
+
gem 'activerecord', '~> 4.2.0'
|
18
|
+
gem 'sqlite3', '< 1.4'
|
19
|
+
end
|
20
|
+
|
21
|
+
if RUBY_VERSION >= '2.2.2'
|
22
|
+
appraise 'rails50' do
|
23
|
+
gem 'activerecord', '~> 5.0.0'
|
24
|
+
gem 'sqlite3', '< 1.4'
|
25
|
+
end
|
26
|
+
|
27
|
+
appraise 'rails51' do
|
28
|
+
gem 'activerecord', '~> 5.1.0'
|
29
|
+
gem 'sqlite3', '< 1.4'
|
30
|
+
end
|
31
|
+
|
32
|
+
appraise 'rails52' do
|
33
|
+
gem 'activerecord', '~> 5.2.0'
|
34
|
+
gem 'sqlite3', '< 1.4'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
if RUBY_VERSION >= '2.6.0'
|
39
|
+
appraise 'rails60' do
|
40
|
+
gem 'activerecord', '~> 6.0.0'
|
41
|
+
end
|
42
|
+
|
43
|
+
appraise 'rails61' do
|
44
|
+
gem 'activerecord', '~> 6.1.0'
|
45
|
+
end
|
46
|
+
end
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,27 @@
|
|
1
|
+
## Unreleased
|
2
|
+
|
3
|
+
## 0.11.0 (Dec 18, 2020)
|
4
|
+
|
5
|
+
* Rails 6.1 をサポート (PR [#37](https://github.com/chocoby/jp_prefecture/pull/37)/[@chocoby](https://github.com/chocoby))
|
6
|
+
* GitHub Actions でビルドを実行するようにした (PR [#34](https://github.com/chocoby/jp_prefecture/pull/34)/[@chocoby](https://github.com/chocoby))
|
7
|
+
|
8
|
+
## 0.10.0 (Aug 19, 2019)
|
9
|
+
|
10
|
+
* Rails 6.0 をサポート (PR [#33](https://github.com/chocoby/jp_prefecture/pull/33)/[@chocoby](https://github.com/chocoby))
|
11
|
+
|
12
|
+
## 0.9.0 (Jan 15, 2017)
|
13
|
+
|
14
|
+
* 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
|
+
* 都道府県情報に種類を追加 (PR [#23](https://github.com/chocoby/jp_prefecture/pull/23)/[@gazayas](https://github.com/gazayas))
|
16
|
+
|
17
|
+
## 0.8.1 (Mar 30, 2016)
|
18
|
+
|
19
|
+
* `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
|
+
|
21
|
+
## 0.8.0 (Sep 07, 2014)
|
22
|
+
|
23
|
+
* 都道府県情報に八地方区分情報を追加 (PR [#14](https://github.com/chocoby/jp_prefecture/pull/14)/[@kkosuge](https://github.com/kkosuge))
|
24
|
+
|
1
25
|
## 0.7.0 (Jun 18, 2014)
|
2
26
|
|
3
27
|
* 都道府県名にひらがな、カタカナを追加 (PR [#12](https://github.com/chocoby/jp_prefecture/pull/12)/[@yukihr](https://github.com/yukihr))
|
data/{LICENSE → MIT-LICENSE}
RENAMED
File without changes
|
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# JpPrefecture
|
2
2
|
|
3
|
-
[
|
4
|
-
|
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
|
|
@@ -51,11 +38,11 @@ require 'jp_prefecture'
|
|
51
38
|
|
52
39
|
### 都道府県コードから都道府県を検索
|
53
40
|
|
54
|
-
|
41
|
+
都道府県コードを渡すと、都道府県コードから都道府県を検索します:
|
55
42
|
|
56
43
|
```ruby
|
57
44
|
pref = JpPrefecture::Prefecture.find 13
|
58
|
-
# => #<JpPrefecture::Prefecture:
|
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
|
61
48
|
pref.name
|
@@ -66,9 +53,13 @@ pref.name_h
|
|
66
53
|
# => "とうきょうと"
|
67
54
|
pref.name_k
|
68
55
|
# => "トウキョウト"
|
56
|
+
pref.area
|
57
|
+
# => "関東"
|
58
|
+
pref.type
|
59
|
+
# => "都"
|
69
60
|
```
|
70
61
|
|
71
|
-
|
62
|
+
以下のように書くことも可能です:
|
72
63
|
|
73
64
|
```ruby
|
74
65
|
JpPrefecture::Prefecture.find code: 13
|
@@ -78,32 +69,21 @@ JpPrefecture::Prefecture.find code: 13
|
|
78
69
|
|
79
70
|
```ruby
|
80
71
|
JpPrefecture::Prefecture.find name: "東京都"
|
81
|
-
# => #<JpPrefecture::Prefecture:0x007fe7bb033040 @code=13, @name="東京都", @name_e="Tokyo", @name_h="とうきょうと", @name_k="トウキョウト", @zips=[1000000..2080035]>
|
82
|
-
|
83
72
|
JpPrefecture::Prefecture.find name: "Tokyo"
|
84
|
-
# => #<JpPrefecture::Prefecture:0x007fe7bb032758 @code=13, @name="東京都", @name_e="Tokyo", @name_h="とうきょうと", @name_k="トウキョウト", @zips=[1000000..2080035]>
|
85
|
-
|
86
73
|
JpPrefecture::Prefecture.find name: "tokyo"
|
87
|
-
# => #<JpPrefecture::Prefecture:0x007fe7bb031e70 @code=13, @name="東京都", @name_e="Tokyo", @name_h="とうきょうと", @name_k="トウキョウト", @zips=[1000000..2080035]>
|
88
|
-
|
89
74
|
JpPrefecture::Prefecture.find name: "トウキョウト"
|
90
|
-
# => #<JpPrefecture::Prefecture:0x007f8cc2038210 @code=13, @name="東京都", @name_e="Tokyo", @name_h="とうきょうと", @name_k="トウキョウト", @zips=[1000000..2080035]>
|
91
|
-
|
92
75
|
JpPrefecture::Prefecture.find name: "とうきょうと"
|
93
|
-
# => #<JpPrefecture::Prefecture:0x007f8cc2033760 @code=13, @name="東京都", @name_e="Tokyo", @name_h="とうきょうと", @name_k="トウキョウト", @zips=[1000000..2080035]>
|
94
|
-
|
95
76
|
JpPrefecture::Prefecture.find name: "東京"
|
96
|
-
# => #<JpPrefecture::Prefecture:0x007fe7bb0305c0 @code=13, @name="東京都", @name_e="Tokyo", @name_h="とうきょうと", @name_k="トウキョウト", @zips=[1000000..2080035]>
|
97
77
|
```
|
98
78
|
|
99
79
|
### 都道府県の一覧を取得
|
100
80
|
|
101
81
|
```ruby
|
102
82
|
JpPrefecture::Prefecture.all
|
103
|
-
# => [#<JpPrefecture::Prefecture:
|
83
|
+
# => [#<JpPrefecture::Prefecture:0x007fceb119a2a8 @code=1, @name="北海道", @name_e="Hokkaido", @name_h="ほっかいどう", @name_k="ホッカイドウ", @zips=[10000..70895, 400000..996509], @area="北海道">, ...]
|
104
84
|
```
|
105
85
|
|
106
|
-
### Rails(ActiveRecord) で使用する
|
86
|
+
### Rails (ActiveRecord) で使用する
|
107
87
|
|
108
88
|
`ActiveRecord::Base` を継承した Model で、都道府県コードを扱うことができます。
|
109
89
|
|
@@ -179,18 +159,33 @@ end
|
|
179
159
|
|
180
160
|
マッピングデータのフォーマットについては [prefecture.yml](https://github.com/chocoby/jp_prefecture/blob/master/data/prefecture.yml) を参考にしてください。
|
181
161
|
|
162
|
+
|
163
|
+
## インストール
|
164
|
+
|
165
|
+
以下の行を `Gemfile` に記述してから:
|
166
|
+
|
167
|
+
```
|
168
|
+
gem 'jp_prefecture'
|
169
|
+
```
|
170
|
+
|
171
|
+
`bundle` を実行してください。
|
172
|
+
|
173
|
+
または、手動でインストールしてください:
|
174
|
+
|
175
|
+
```
|
176
|
+
$ gem install jp_prefecture
|
177
|
+
```
|
178
|
+
|
179
|
+
|
182
180
|
## ドキュメント
|
183
181
|
|
184
182
|
[http://rdoc.info/github/chocoby/jp_prefecture/master/frames/index](http://rdoc.info/github/chocoby/jp_prefecture/master/frames/index)
|
185
183
|
|
186
|
-
##
|
184
|
+
## サポートしているバージョン
|
187
185
|
|
188
|
-
|
186
|
+
* Ruby: 1.9.3 / 2.0 / 2.1 / 2.2 / 2.3 / 2.4 / 2.5 / 2.6 / 2.7
|
187
|
+
* Rails: 3.2 / 4.0 / 4.1 / 4.2 / 5.0 / 5.1 / 5.2 / 6.0 / 6.1
|
189
188
|
|
190
|
-
## 対象バージョン
|
191
|
-
|
192
|
-
* Ruby: 1.9.3 / 2.0 / 2.1
|
193
|
-
* Rails: 3.2 / 4.0 / 4.1
|
194
189
|
|
195
190
|
## Contributing
|
196
191
|
|
@@ -200,10 +195,24 @@ GitHub の [Issues](https://github.com/chocoby/jp_prefecture/issues) を参照
|
|
200
195
|
4. Push to the branch (`git push origin my-new-feature`)
|
201
196
|
5. Create new Pull Request
|
202
197
|
|
203
|
-
## GitHub
|
204
198
|
|
205
|
-
|
199
|
+
## テスト
|
206
200
|
|
207
|
-
|
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 でテストを実行:
|
208
209
|
|
209
|
-
|
210
|
+
```
|
211
|
+
bundle exec appraisal install
|
212
|
+
bundle exec appraisal rspec
|
213
|
+
```
|
214
|
+
|
215
|
+
|
216
|
+
## GitHub
|
217
|
+
|
218
|
+
https://github.com/chocoby/jp_prefecture
|
data/README_EN.md
ADDED
@@ -0,0 +1,219 @@
|
|
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
|
+
```ruby
|
68
|
+
JpPrefecture::Prefecture.find name: "東京都"
|
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: "東京"
|
74
|
+
```
|
75
|
+
|
76
|
+
### All Prefectures
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
JpPrefecture::Prefecture.all
|
80
|
+
# => [#<JpPrefecture::Prefecture:0x007fceb119a2a8 @code=1, @name="北海道", @name_e="Hokkaido", @name_h="ほっかいどう", @name_k="ホッカイドウ", @zips=[10000..70895, 400000..996509], @area="北海道">, ...]
|
81
|
+
```
|
82
|
+
|
83
|
+
### Usage on Rails (ActiveRecord)
|
84
|
+
|
85
|
+
Include JpPrefecture to Model which `ActiveRecord::Base` inherited.
|
86
|
+
|
87
|
+
app/models/place.rb:
|
88
|
+
|
89
|
+
```ruby
|
90
|
+
class Place < ActiveRecord::Base
|
91
|
+
# prefecture_code:integer
|
92
|
+
|
93
|
+
include JpPrefecture
|
94
|
+
jp_prefecture :prefecture_code
|
95
|
+
end
|
96
|
+
```
|
97
|
+
|
98
|
+
By JpPrefecture included, `prefecture` method will be generated:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
place = Place.new
|
102
|
+
place.prefecture_code = 13
|
103
|
+
place.prefecture.name_e
|
104
|
+
# => "Tokyo"
|
105
|
+
```
|
106
|
+
|
107
|
+
Customize `prefecture` method name with `method_name` option:
|
108
|
+
|
109
|
+
```ruby
|
110
|
+
# model
|
111
|
+
jp_prefecture :prefecture_code, method_name: :pref
|
112
|
+
|
113
|
+
place = Place.new
|
114
|
+
place.prefecture_code = 13
|
115
|
+
place.pref.name_e
|
116
|
+
# => "Tokyo"
|
117
|
+
```
|
118
|
+
|
119
|
+
### Template usage
|
120
|
+
|
121
|
+
Use `collection_select` to generate selector in view:
|
122
|
+
|
123
|
+
```ruby
|
124
|
+
# Selector prefecture name in English
|
125
|
+
f.collection_select :prefecture_code, JpPrefecture::Prefecture.all, :code, :name_e
|
126
|
+
|
127
|
+
# Selector prefecture name in Japanese
|
128
|
+
f.collection_select :prefecture_code, JpPrefecture::Prefecture.all, :code, :name
|
129
|
+
```
|
130
|
+
|
131
|
+
### Migration
|
132
|
+
|
133
|
+
Set `prefecture_code` column type to `integer` or `string`.
|
134
|
+
|
135
|
+
Example:
|
136
|
+
|
137
|
+
```ruby
|
138
|
+
class AddPrefectureCodeToPlaces < ActiveRecord::Migration
|
139
|
+
def change
|
140
|
+
add_column :places, :prefecture_code, :integer
|
141
|
+
end
|
142
|
+
end
|
143
|
+
```
|
144
|
+
|
145
|
+
### Customize Mapping Data
|
146
|
+
|
147
|
+
Customize mapping data with `custom_mapping_path`.
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
custom_mapping_path = "..." # /path/to/mapping_data
|
151
|
+
|
152
|
+
JpPrefecture.setup do |config|
|
153
|
+
config.mapping_data = YAML.load_file custom_mapping_path
|
154
|
+
end
|
155
|
+
```
|
156
|
+
|
157
|
+
Check out [prefecture.yml](https://github.com/chocoby/jp_prefecture/blob/master/data/prefecture.yml) for data format.
|
158
|
+
|
159
|
+
|
160
|
+
## Installation
|
161
|
+
|
162
|
+
Add this line in Gemfile.
|
163
|
+
|
164
|
+
```ruby
|
165
|
+
gem 'jp_prefecture'
|
166
|
+
```
|
167
|
+
|
168
|
+
Run
|
169
|
+
|
170
|
+
```
|
171
|
+
$ bundle
|
172
|
+
```
|
173
|
+
|
174
|
+
Or install gem with `gem install`
|
175
|
+
|
176
|
+
```
|
177
|
+
$ gem install jp_prefecture
|
178
|
+
```
|
179
|
+
|
180
|
+
|
181
|
+
## Documentation
|
182
|
+
|
183
|
+
[http://rdoc.info/github/chocoby/jp_prefecture/master/frames/index](http://rdoc.info/github/chocoby/jp_prefecture/master/frames/index)
|
184
|
+
|
185
|
+
## Supports
|
186
|
+
|
187
|
+
* Ruby: 1.9.3 / 2.0 / 2.1 / 2.2 / 2.3 / 2.4 / 2.5 / 2.6 / 2.7
|
188
|
+
* Rails: 3.2 / 4.0 / 4.1 / 4.2 / 5.0 / 5.1 / 5.2 / 6.0 / 6.1
|
189
|
+
|
190
|
+
|
191
|
+
## Contributing
|
192
|
+
|
193
|
+
1. Fork it
|
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
|
+
|
216
|
+
|
217
|
+
## GitHub
|
218
|
+
|
219
|
+
https://github.com/chocoby/jp_prefecture
|