jp_local_gov 0.1.0 → 0.3.1

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
2
  SHA256:
3
- metadata.gz: 4860d4939032f21410e79a628f6000fd037f755e9997903e670e8a9195c272c9
4
- data.tar.gz: 2f263d1c09e9db4e138fbaac8bd31bc10f26692bf1bd6b2a1ee07a9c4f879578
3
+ metadata.gz: 4f627a940405e1c5f1339526132b70637a1e4243546d550bd6710f7c71339d19
4
+ data.tar.gz: e40ce4f88624c7abe41bf365feb0d64567b96d63449737618c7acbc4c6b563d4
5
5
  SHA512:
6
- metadata.gz: af1984c55d50f4368dfda951e6cc2a18e4a564e54002da1728b1a5c12baeeaddfe89efd38bd36c759d1ce5ff5966f0870eb7e35e42315b703c112eb056cc599d
7
- data.tar.gz: ee7b9dc6f8cca9f271a173acac5052a517c9882fb34911f12503782879e29c5239aa3773ea856d5765550b5e8965ad059863f2686e49a36f7200cfa3d18e9c68
6
+ metadata.gz: 468b26d385a1cc82a35c993b29cea69e9991e3d0ca28a2d4cac02ab15dd9a1ea195b732a717a320e15f8eee365bab779a4691212614cbb166b672d0406431e3c
7
+ data.tar.gz: 9d1850d5b14e67260e4a83ec7da3ca2a3c9041f6bebfdae2abc34be71030c63eec171321c84766f56e51c95f863f24a5cdcdf3c4670d320130537097e1797587
@@ -0,0 +1,50 @@
1
+ name: BugReport
2
+ description: File a bug report
3
+ title: "[Bug]: "
4
+ assignees: IkumaTadokoro
5
+ labels: ["bug"]
6
+ body:
7
+ - type: markdown
8
+ attributes:
9
+ value: "Thanks for taking the time to fill out this bug report!"
10
+ - type: textarea
11
+ id: description
12
+ attributes:
13
+ label: Summary
14
+ validations:
15
+ required: false
16
+ - type: textarea
17
+ id: reproduction
18
+ attributes:
19
+ label: Steps to reproduce the bug
20
+ placeholder: |
21
+ 1. ...
22
+ 2. ...
23
+ 3. ...
24
+ validations:
25
+ required: false
26
+ - type: textarea
27
+ id: expected
28
+ attributes:
29
+ label: Expected
30
+ validations:
31
+ required: false
32
+ - type: textarea
33
+ id: log
34
+ attributes:
35
+ label: Relevant log output
36
+ description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks.
37
+ render: shell
38
+ validations:
39
+ required: false
40
+ - type: textarea
41
+ id: environment
42
+ attributes:
43
+ label: Environment
44
+ validations:
45
+ required: false
46
+ - type: textarea
47
+ id: related_issues
48
+ attributes:
49
+ label: Related Issue
50
+ placeholder: "Ref: #3899"
@@ -0,0 +1,22 @@
1
+ name: Feature Suggestion
2
+ description: Suggestions for new feature
3
+ assignees: IkumaTadokoro
4
+ title: "[Feature]: "
5
+ labels: ["enhancement"]
6
+ body:
7
+ - type: markdown
8
+ attributes:
9
+ value: "Thanks for taking the time to fill out this feature proposal!"
10
+ - type: textarea
11
+ id: description
12
+ attributes:
13
+ label: Description of new feature
14
+ validations:
15
+ required: false
16
+ - type: textarea
17
+ id: reason
18
+ attributes:
19
+ label: Reason
20
+ description: Please fill out the reason why your idea should be adopted.
21
+ validations:
22
+ required: false
@@ -0,0 +1,15 @@
1
+ {
2
+ "problemMatcher": [
3
+ {
4
+ "owner": "codespell",
5
+ "pattern": [
6
+ {
7
+ "regexp": "^.+/(.+?):(\\d+): (.+)$",
8
+ "file": 1,
9
+ "line": 2,
10
+ "message": 3
11
+ }
12
+ ]
13
+ }
14
+ ]
15
+ }
@@ -0,0 +1,15 @@
1
+ {
2
+ "problemMatcher": [
3
+ {
4
+ "owner": "misspell",
5
+ "pattern": [
6
+ {
7
+ "regexp": "^(.+):(\\d+):\\d+: (.+)$",
8
+ "file": 1,
9
+ "line": 2,
10
+ "message": 3
11
+ }
12
+ ]
13
+ }
14
+ ]
15
+ }
@@ -13,6 +13,7 @@ jobs:
13
13
  - name: Set up Ruby
14
14
  uses: ruby/setup-ruby@v1
15
15
  with:
16
+ ruby-version: 3.1
16
17
  bundler-cache: true # runs 'bundle install' and caches installed gems automatically
17
18
  - name: update jplocalgov data
18
19
  run: bundle exec rake jplocalgov:data:update_all
@@ -9,12 +9,15 @@ on:
9
9
  jobs:
10
10
  lint:
11
11
  runs-on: ubuntu-latest
12
-
12
+ strategy:
13
+ matrix:
14
+ ruby: [2.7, '3.0', 3.1]
13
15
  steps:
14
16
  - uses: actions/checkout@v2
15
17
  - name: Set up Ruby
16
18
  uses: ruby/setup-ruby@v1
17
19
  with:
20
+ ruby-version: ${{ matrix.ruby }}
18
21
  bundler-cache: true
19
22
 
20
23
  - name: Rubocop
@@ -0,0 +1,44 @@
1
+ name: Spell Checking
2
+
3
+ on:
4
+ push:
5
+ branches: ["main"]
6
+ tags: ["**"]
7
+ pull_request:
8
+ branches: ["main"]
9
+
10
+ jobs:
11
+ codespell:
12
+ name: Check spelling all files with codespell
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ matrix:
16
+ python-version: [3.8]
17
+ steps:
18
+ - uses: actions/checkout@v2
19
+ - name: Set up Python ${{ matrix.python-version }}
20
+ uses: actions/setup-python@v2
21
+ with:
22
+ python-version: ${{ matrix.python-version }}
23
+ - name: Install dependencies
24
+ run: |
25
+ python -m pip install --upgrade pip
26
+ pip install codespell
27
+ if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
28
+ - name: enable problem matcher
29
+ run: |
30
+ echo "::add-matcher::.github/codespell-problem-matcher.json"
31
+ - name: Check spelling with codespell
32
+ run: codespell --ignore-words=codespell.txt || exit 1
33
+ misspell:
34
+ name: Check spelling all files in commit with misspell
35
+ runs-on: ubuntu-latest
36
+ steps:
37
+ - uses: actions/checkout@v2
38
+ - name: Install
39
+ run: wget -O - -q https://git.io/misspell | sh -s -- -b .
40
+ - name: enable problem matcher
41
+ run: |
42
+ echo "::add-matcher::.github/misspell-problem-matcher.json"
43
+ - name: Misspell
44
+ run: git ls-files --empty-directory | xargs ./misspell -i 'enviromnent' -error
@@ -10,10 +10,14 @@ on:
10
10
  jobs:
11
11
  check:
12
12
  runs-on: ubuntu-latest
13
+ strategy:
14
+ matrix:
15
+ ruby: [2.7, '3.0', 3.1]
13
16
  steps:
14
17
  - uses: actions/checkout@v2
15
18
  - uses: ruby/setup-ruby@v1
16
19
  with:
20
+ ruby-version: ${{ matrix.ruby }}
17
21
  bundler-cache: true
18
22
  - run: bundle exec appraisal install
19
23
  - run: |
@@ -21,10 +25,14 @@ jobs:
21
25
  shell: bash
22
26
  stats:
23
27
  runs-on: ubuntu-latest
28
+ strategy:
29
+ matrix:
30
+ ruby: [2.7, '3.0', 3.1]
24
31
  steps:
25
32
  - uses: actions/checkout@v2
26
33
  - uses: ruby/setup-ruby@v1
27
34
  with:
35
+ ruby-version: ${{ matrix.ruby }}
28
36
  bundler-cache: true
29
37
  - run: bundle exec appraisal install
30
38
  - run: bundle exec rake steep:stats
@@ -7,14 +7,17 @@ on:
7
7
  branches: ["main"]
8
8
 
9
9
  jobs:
10
- lint:
10
+ test:
11
11
  runs-on: ubuntu-latest
12
-
12
+ strategy:
13
+ matrix:
14
+ ruby: [2.7, '3.0', 3.1]
13
15
  steps:
14
16
  - uses: actions/checkout@v2
15
17
  - name: Set up Ruby
16
18
  uses: ruby/setup-ruby@v1
17
19
  with:
20
+ ruby-version: ${{ matrix.ruby }}
18
21
  bundler-cache: true
19
22
  - run: bundle exec appraisal install
20
23
  - run: bundle exec appraisal rspec
data/.gitignore CHANGED
@@ -5,7 +5,6 @@
5
5
  /doc/
6
6
  /pkg/
7
7
  /spec/reports/
8
- /tmp/
9
8
  vendor/bundle
10
9
 
11
10
  # rspec failure tracking
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 3.0
2
+ TargetRubyVersion: 2.7
3
3
 
4
4
  Style/StringLiterals:
5
5
  Enabled: true
@@ -9,6 +9,14 @@ Style/StringLiteralsInInterpolation:
9
9
  Enabled: true
10
10
  EnforcedStyle: double_quotes
11
11
 
12
+ Metrics/BlockLength:
13
+ Exclude:
14
+ - spec/**/*
15
+
16
+ Metrics/ClassLength:
17
+ Exclude:
18
+ - spec/**/*
19
+
12
20
  Layout/LineLength:
13
21
  Max: 120
14
22
 
data/CHANGELOG.md CHANGED
@@ -1,5 +1,64 @@
1
- ## [Unreleased]
1
+ # [0.3.1](https://github.com/IkumaTadokoro/jp_local_gov/compare/v0.3.0...v0.3.1) (2022-02-03)
2
2
 
3
- ## [0.1.0] - 2021-11-28
3
+
4
+ ### feat
5
+
6
+ * Specify ruby version in auto-update workflow ([572fc5e](https://github.com/IkumaTadokoro/jp_local_gov/commit/572fc5e3cd316f5d194dc8affdbf161acd3b864f)), closes [#77](https://github.com/IkumaTadokoro/jp_local_gov/issues/77) [#79](https://github.com/IkumaTadokoro/jp_local_gov/issues/79)
7
+
8
+ ### fix
9
+
10
+ * Fix JpLocalGov.valid_code?'s condition ([5e1ccf4](https://github.com/IkumaTadokoro/jp_local_gov/commit/5e1ccf4415d5e2e5752d904334e07b550e0d6d5d)), closes [#85](https://github.com/IkumaTadokoro/jp_local_gov/issues/85)
11
+
12
+ # [0.3.0](https://github.com/IkumaTadokoro/jp_local_gov/compare/v0.2.1...v0.3.0) (2022-01-28)
13
+
14
+ ### feat
15
+
16
+ * Loosen Ruby version requirement to 2.7.0 ([e3d5f6da](https://github.com/IkumaTadokoro/jp_local_gov/commit/e3d5f6dafcb6665444e81289fcb91ce7d4365a3a))
17
+ * Removing `.ruby-version` file lets other devs to use their preferred version of Ruby ([3b3bd483](https://github.com/IkumaTadokoro/jp_local_gov/commit/3b3bd483c167266338fe07d627d58de3d833b37d))
18
+
19
+ ## [0.2.1](https://github.com/IkumaTadokoro/jp_local_gov/compare/v0.2.0...v0.2.1) (2022-01-14)
20
+
21
+ ### docs
22
+
23
+ * Add how to use JpLocalGov::Random ([aab920b](https://github.com/IkumaTadokoro/jp_local_gov/commit/aab920bc1e460eb7105f4759fcca1f8a8e06b9f7)), closes [#66](https://github.com/IkumaTadokoro/jp_local_gov/issues/66)
24
+
25
+ ### fix
26
+
27
+ * Fix dependency of JpLocalGov::Random ([6da699b](https://github.com/IkumaTadokoro/jp_local_gov/commit/6da699b9b49c53551e704f0d05cdd269a4566727)), closes [#70](https://github.com/IkumaTadokoro/jp_local_gov/issues/70)
28
+
29
+ ## [0.2.0](https://github.com/IkumaTadokoro/jp_local_gov/compare/v0.1.0...v0.2.0) (2022-01-14)
30
+
31
+ ### chore
32
+
33
+ * Add RSpec Runner for JetBrains IDE ([83d8c86](https://github.com/IkumaTadokoro/jp_local_gov/commit/83d8c8649f69506c9a08acf275960480316eb988))
34
+ * Make JpLocalGov::Data::Importer#prefecture_capital? to return true/false ([82daafd](https://github.com/IkumaTadokoro/jp_local_gov/commit/82daafd19b47e52ff2c1c341a243aef7e5dffae4))
35
+
36
+ ### ci
37
+
38
+ * Add spell checking GitHub Actions Workflow ([fc23bd1](https://github.com/IkumaTadokoro/jp_local_gov/commit/fc23bd1a3c10cc49f8aaf4e869c0062b50255f03))
39
+
40
+ ### docs
41
+
42
+ * 💅 ([61c6d66](https://github.com/IkumaTadokoro/jp_local_gov/commit/61c6d66a43b75339036656a1b110dec97156177e))
43
+ * Add how to use JpLocalGov.valid_code? ([2e14d71](https://github.com/IkumaTadokoro/jp_local_gov/commit/2e14d71c146d823e4bc3fa268da2e3a0c5f7ebe1))
44
+ * Add issue template ([9f416a3](https://github.com/IkumaTadokoro/jp_local_gov/commit/9f416a335247c3be5c52e450b914bd73c380092d)), closes [#47](https://github.com/IkumaTadokoro/jp_local_gov/issues/47)
45
+
46
+ ### feat
47
+
48
+ * Add JpLocalGov::Random module ([bae16d7](https://github.com/IkumaTadokoro/jp_local_gov/commit/bae16d7b8ebeff1871b2b5586f0b916253c462e7)), closes [#65](https://github.com/IkumaTadokoro/jp_local_gov/issues/65)
49
+ * Add JpLocalGov.all_xxx ([f522686](https://github.com/IkumaTadokoro/jp_local_gov/commit/f52268612a5c41435e4a20f3759c9d7d70686a62)), closes [#54](https://github.com/IkumaTadokoro/jp_local_gov/issues/54)
50
+ * Make JpLocalGov.valid_code? public ([e46b4e7](https://github.com/IkumaTadokoro/jp_local_gov/commit/e46b4e79f3fd0098bd2b509123f866a92c01ee37)), closes [#55](https://github.com/IkumaTadokoro/jp_local_gov/issues/55)
51
+
52
+ ### fix
53
+
54
+ * Fix a task(`jp_local_gov:data:update_all`) ([e21125c](https://github.com/IkumaTadokoro/jp_local_gov/commit/e21125cda74c62e7b45b528ee0f908cfbab6b039)), closes [#60](https://github.com/IkumaTadokoro/jp_local_gov/issues/60)
55
+
56
+ ### style
57
+
58
+ * Add rubocop-rake and rubocop-rspec ([eb5f7d2](https://github.com/IkumaTadokoro/jp_local_gov/commit/eb5f7d22066a65d41d112e60dc8fc7c9b8b71c47))
59
+ * omit parentheses for internal DSL(RSpec) ([3c23ec5](https://github.com/IkumaTadokoro/jp_local_gov/commit/3c23ec5a19460e2c8ed496b61536ebd800cfeb03))
60
+ * Remove Metrics rule for spec ([e362565](https://github.com/IkumaTadokoro/jp_local_gov/commit/e3625658376a6b0fd8ac5cea97b0d857cd6f6e7b))
61
+
62
+ ## 0.1.0 (2021-11-28)
4
63
 
5
64
  - Initial release
data/Gemfile CHANGED
@@ -15,6 +15,8 @@ group :development do
15
15
  gem "rbs"
16
16
  gem "rubocop"
17
17
  gem "rubocop-fjord"
18
+ gem "rubocop-rake"
19
+ gem "rubocop-rspec"
18
20
  gem "sqlite3"
19
21
  gem "steep"
20
22
  end
data/README.md CHANGED
@@ -1,8 +1,25 @@
1
+ [![Gem Version](https://badge.fury.io/rb/jp_local_gov.svg)](https://badge.fury.io/rb/jp_local_gov)
2
+ [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](https://github.com/IkumaTadokoro/jp_local_gov/blob/main/LICENSE.txt)
3
+ ![Gem](https://img.shields.io/gem/dt/jp_local_gov)
4
+
1
5
  # JpLocalGov
2
6
 
3
7
  Convert local government code based on JIS X 0402 to local government name in Japan.
4
8
  Reference(Japanese): [全国地方公共団体コード \- Wikipedia](https://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)
5
9
 
10
+ ### Issues
11
+
12
+ If you find any bugs or concerns, or have suggestions for new features, please feel free to add them as an [GitHub Issue](https://github.com/IkumaTadokoro/jp_local_gov/issues/new/choose)!
13
+
14
+ There are issue templates for bug and feature. If neither, please use the blank template.
15
+
16
+ ### Special Thanks
17
+
18
+ This gem is based on and inspired by [chocoby/jp_prefecture](https://github.com/chocoby/jp_prefecture).
19
+ And I referenced [kufu/jpostcode-data](https://github.com/kufu/jpostcode-data) for the method of data acquisition.
20
+
21
+ Thanks!😁
22
+
6
23
  ## Installation
7
24
 
8
25
  Add this line to your application's Gemfile:
@@ -60,7 +77,7 @@ This search function is an exact match search.
60
77
 
61
78
  ```ruby
62
79
  misato = JpLocalGov.where(city: "美郷町")
63
- # => [#<JpLocalGov::LocalGov:0x00007fb1c594cb08 @code="054348", @prefecture_code="05", @prefecture="秋田県", @prefecture_kana="アキタケン", @city="美郷町", @city_kana="ミサトチョウ", @prefecture_capital=false>, #<JpLocalGov::LocalGov:8 @code="324485", @prefecture_code="32", @prefecture="島根県", @prefecture_kana="シマネケン", @city="美郷町", @city_kana="ミサトチョウ", @prefecture_capital=false>, #<JpLocalGov::LocalGov:0x00007fb1c1a3ce40 @code="454311", @prefectuefecture="宮崎県", @prefecture_kana="ミヤザキケン", @city="美郷町", @city_kana="ミサトチョウ", @prefecture_capital=false>]
80
+ # => [#<JpLocalGov::LocalGov:0x00007fb1c594cb08 @code="054348", @prefecture_code="05", @prefecture="秋田県", @prefecture_kana="アキタケン", @city="美郷町", @city_kana="ミサトチョウ", @prefecture_capital=false>, #<JpLocalGov::LocalGov:8 @code="324485", @prefecture_code="32", @prefecture="島根県", @prefecture_kana="シマネケン", @city="美郷町", @city_kana="ミサトチョウ", @prefecture_capital=false>, #<JpLocalGov::LocalGov:0x00007fb1c1a3ce40 @code="454311", @prefecture="宮崎県", @prefecture_kana="ミヤザキケン", @city="美郷町", @city_kana="ミサトチョウ", @prefecture_capital=false>]
64
81
  misato.map { "#{_1.prefecture}:#{_1.city}" }
65
82
  # => ["秋田県:美郷町", "島根県:美郷町", "宮崎県:美郷町"]
66
83
 
@@ -84,13 +101,43 @@ The following attributes can be specified for the condition.
84
101
  | city_kana | String | "チヨダク" |
85
102
  | prefecture_capital | true or false | false |
86
103
 
104
+ ### All data
105
+
106
+ You can get all local governments using `JpLocalGov.all`
107
+
108
+ ```ruby
109
+ JpLocalGov.all
110
+ # => [#<JpLocalGov::LocalGov:0x00007fdf3a9c6758 @code="011002", @prefecture_code="01", @prefecture="北海道", @prefecture_kana="ホッカイドウ", @city="札幌市na="サッポロシ", @prefecture_capital=true>, #<JpLocalGov::LocalGov:0x00007fdf3a9c6730 @code="011011",...
111
+ ```
112
+
113
+ ### Random data
114
+
115
+ You can create random `code`, `city`, `city_kana`, `prefecture`, `prefecture_code` and `prefecture_kana` by using `JpLocalGov::Random`.
116
+
117
+ ```ruby
118
+ JpLocalGov::Random.code
119
+ # => "281077"
120
+ JpLocalGov::Random.city
121
+ # => "大島町"
122
+ JpLocalGov::Random.city_kana
123
+ # => "チュウオウシ"
124
+ JpLocalGov::Random.prefecture
125
+ # => "青森県"
126
+ JpLocalGov::Random.prefecture_code
127
+ # => "46"
128
+ JpLocalGov::Random.prefecture_kana
129
+ # => "ヒョウゴケン"
130
+ ```
131
+
132
+ It is useful to random factory data in rails app for example.
133
+
87
134
  ### Usage on Rails (ActiveRecord)
88
135
 
89
136
  Include JpLocalGov to Model which ActiveRecord::Base inherited.
90
137
 
91
138
  ```ruby
92
- # app/models/insurrance_fees.rb:
93
- class Place < ActiveRecord::Base
139
+ # app/models/insurance_fee.rb:
140
+ class InsuranceFee < ActiveRecord::Base
94
141
  # local_gov_code:String
95
142
 
96
143
  include JpLocalGov
@@ -110,13 +157,43 @@ insurance_fee.local_government.city
110
157
  In Migration file, set `local_gov_code` column type to `string`.
111
158
 
112
159
  ```ruby
113
- class AddLocalGovCodeToinsuranceFees < ActiveRecord::Migration
160
+ class AddLocalGovCodeToInsuranceFees < ActiveRecord::Migration
114
161
  def change
115
162
  add_column :insurance_fees, :local_gov_code, :string
116
163
  end
117
164
  end
118
165
  ```
119
166
 
167
+ ### Validation
168
+
169
+ You can use `JpLocalGov.valid_code?(local_gov_code)` in `validate` method.
170
+
171
+ ```ruby
172
+ class InsuranceFee < ApplicationRecord
173
+ include JpLocalGov
174
+ jp_local_gov :local_gov_code
175
+
176
+ validate :valid_code?
177
+
178
+ def valid_code?
179
+ unless JpLocalGov.valid_code?(local_gov_code)
180
+ errors.add(:local_gov_code, "is not valid code")
181
+ end
182
+ end
183
+ end
184
+ ```
185
+
186
+ This method inspect code by [check digits defined in JISX0402](https://www.soumu.go.jp/main_content/000137948.pdf).
187
+ (And also check code is String.)
188
+
189
+ ### View Template
190
+
191
+ Use `collection_select` to generate selector in view:
192
+
193
+ ```ruby
194
+ f.collection_select :local_gov_code, JpLocalGov.all, :code, :city # e.g. code: 131016, city: "千代田区"
195
+ ```
196
+
120
197
  ## Development
121
198
 
122
199
  ### Steps
@@ -138,9 +215,62 @@ end
138
215
  | `bin/lint` | Run Rubocop |
139
216
  | `bin/steep` | Run `steep stats` and `steep check` |
140
217
 
218
+ ### Running Test via JetBrains IDE (e.g. RubyMine)
219
+
220
+ This gem use 'Appraisal' to inspect several versions of Rails.
221
+
222
+ So you should run rspec by `bundle exec appraisal rspec` and you won't be able to run spec via IDE (only run via your
223
+ terminal).
224
+
225
+ If you use JetBrains IDE and you want to run spec via IDE, try to configure the following steps.
226
+
227
+ 1. Open 「Edit Configurations...」
228
+ 2. Open 「Edit Configuration templates...」
229
+ 3. Select 「RSpec」
230
+ 4. Check 「Use custom RSpec runner script:」 and fill the script with `[CLONE_DIR]/bin/spec_runner.rb`
231
+ 5. Click「APPLY」, then you can run spec via IDE!!🎉
232
+
233
+ If you have already run spec via IDE before configuration, delete the existing configuration and try to configure the
234
+ above steps
235
+
236
+ ## Update local government data
237
+
238
+ This Gem update local government data (format: JSON) automatically once a month by [GitHub Actions](https://github.com/IkumaTadokoro/jp_local_gov/actions/workflows/auto-update.yml).
239
+
240
+ - Data source: https://www.soumu.go.jp/denshijiti/code.html
241
+ - Output: https://github.com/IkumaTadokoro/jp_local_gov/tree/main/data/json
242
+
243
+ Fetch script is written in Ruby and Rake Task. So you can run update data at local by the following command.
244
+
245
+ ```ruby
246
+ bundle exec rake jp_local_gov:data:update_all
247
+ ```
248
+
141
249
  ## Contributing
142
250
 
143
- Bug reports and pull requests are welcome on GitHub at https://github.com/IkumaTadokoro/jp_local_gov. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/IkumaTadokoro/jp_local_gov/blob/main/CODE_OF_CONDUCT.md).
251
+ Bug reports and pull requests are welcome on GitHub at https://github.com/IkumaTadokoro/jp_local_gov. This project is
252
+ intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to
253
+ the [code of conduct](https://github.com/IkumaTadokoro/jp_local_gov/blob/main/CODE_OF_CONDUCT.md).
254
+
255
+ ### Spell Checking
256
+
257
+ We are running [misspell](https://github.com/client9/misspell) which is mainly written in
258
+ [Golang](https://golang.org/) to check spelling with [GitHub Actions](../.github/workflows/spell-checking.yml). Correct
259
+ commonly misspelled English words quickly with `misspell`. `misspell` is different from most other spell checkers
260
+ because it doesn't use a custom dictionary. You can run `misspell` locally against all files with:
261
+
262
+ $ find . -type f | xargs ./misspell -error
263
+
264
+ Notable `misspell` help options or flags are:
265
+
266
+ * `-i` string: ignore the following corrections, comma separated
267
+ * `-w`: Overwrite file with corrections (default is just to display)
268
+
269
+ We also run [codespell](https://github.com/codespell-project/codespell) with GitHub Actions to check spelling and
270
+ [codespell](https://pypi.org/project/codespell/) runs against a [small custom dictionary](../codespell.txt).
271
+ `codespell` is written in [Python](https://www.python.org/) and you can run it with:
272
+
273
+ $ codespell --ignore-words=codespell.txt
144
274
 
145
275
  ## License
146
276
 
@@ -148,4 +278,5 @@ The gem is available as open source under the terms of the [MIT License](https:/
148
278
 
149
279
  ## Code of Conduct
150
280
 
151
- Everyone interacting in the JpLocalGov project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/IkumaTadokoro/jp_local_gov/blob/main/CODE_OF_CONDUCT.md).
281
+ Everyone interacting in the JpLocalGov project's codebases, issue trackers, chat rooms and mailing lists is expected to
282
+ follow the [code of conduct](https://github.com/IkumaTadokoro/jp_local_gov/blob/main/CODE_OF_CONDUCT.md).
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ # !/usr/bin/env ruby
4
+
5
+ # Most of the code here is copied from /lib/appraisal/cli.rb in the appraisal gem library
6
+ require "rubygems"
7
+ require "bundler/setup"
8
+ require "appraisal"
9
+ require "appraisal/cli"
10
+
11
+ begin
12
+ `bundle exec appraisal list`.split(/\R/) do |appraisal_name|
13
+ cmd = [appraisal_name, "rspec"] + ARGV
14
+ Appraisal::CLI.start(cmd)
15
+ end
16
+ rescue Appraisal::AppraisalsNotFound => e
17
+ puts e.message
18
+ exit 127
19
+ end
data/codespell.txt ADDED
File without changes
data/data/importer.rb CHANGED
@@ -56,7 +56,7 @@ module JpLocalGov
56
56
 
57
57
  def prefecture_capital?(prefecture, city)
58
58
  prefecture_capital_list = JSON.parse(File.open(File.expand_path("prefecture_capital.json", __dir__)).read)
59
- prefecture_capital_list.find do |prefecture_capital|
59
+ prefecture_capital_list.any? do |prefecture_capital|
60
60
  prefecture_capital["prefecture"] == prefecture && prefecture_capital["city"] == city
61
61
  end
62
62
  end
data/jp_local_gov.gemspec CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
12
12
  spec.description = "Convert japan local government code (JIS X 0402 based) into the local government name."
13
13
  spec.homepage = "https://github.com/IkumaTadokoro/jp_local_gov"
14
14
  spec.license = "MIT"
15
- spec.required_ruby_version = ">= 3.0.0"
15
+ spec.required_ruby_version = ">= 2.7.0"
16
16
 
17
17
  # Specify which files should be added to the gem when it is released.
18
18
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../jp_local_gov"
4
+
5
+ module JpLocalGov
6
+ module Random
7
+ DATA_DIR = "#{File.dirname(__FILE__)}/../../data/json/"
8
+ RANDOMIZE_TARGET = %w[code city city_kana prefecture prefecture_code prefecture_kana].freeze
9
+
10
+ module_function
11
+
12
+ RANDOMIZE_TARGET.each do |target|
13
+ define_method target.to_s do
14
+ sample_data.send(target)
15
+ end
16
+ end
17
+
18
+ def sample_data
19
+ file_name = ("1".."47").to_a.sample&.rjust(2, "0")
20
+ json_file = "#{DATA_DIR}#{file_name}.json"
21
+ data = JSON.parse(File.read(json_file), { symbolize_names: true })
22
+ JpLocalGov::LocalGov.new(data[data.keys.sample])
23
+ end
24
+
25
+ private_class_method :sample_data
26
+ private_constant :DATA_DIR, :RANDOMIZE_TARGET
27
+ end
28
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JpLocalGov
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.1"
5
5
  end
data/lib/jp_local_gov.rb CHANGED
@@ -3,12 +3,15 @@
3
3
  require_relative "jp_local_gov/version"
4
4
  require_relative "jp_local_gov/local_gov"
5
5
  require_relative "jp_local_gov/base"
6
+ require_relative "jp_local_gov/random"
6
7
  require "json"
7
8
 
8
9
  module JpLocalGov
9
- DATA_DIR = "#{File.dirname(__FILE__)}/../data/json/".freeze
10
+ DATA_DIR = "#{File.dirname(__FILE__)}/../data/json/"
10
11
  CHECK_DIGITS_INDEX = 5
11
12
  CHECK_BASE = 11
13
+ PREFECTURE_RANGE = (1..47).freeze
14
+ VALID_CODE_LENGTH = 6
12
15
 
13
16
  module_function
14
17
 
@@ -17,10 +20,10 @@ module JpLocalGov
17
20
  end
18
21
 
19
22
  def find(local_gov_code)
20
- return nil unless local_gov_code.is_a?(String) && valid_code?(local_gov_code)
23
+ return nil unless valid_code?(local_gov_code)
21
24
 
22
25
  json_file = "#{DATA_DIR}#{local_gov_code[0..1]}.json"
23
- data = JSON.parse(File.open(json_file).read, { symbolize_names: true })
26
+ data = json_data_from(json_file)
24
27
  local_gov_data = data[local_gov_code.to_sym]
25
28
  return nil if local_gov_data.nil?
26
29
 
@@ -30,9 +33,9 @@ module JpLocalGov
30
33
  def where(conditions)
31
34
  return nil unless conditions.is_a?(Hash)
32
35
 
33
- json_files = [*1..47].map { format("%02<number>d", number: _1) }.map { "#{DATA_DIR}#{_1}.json" }
36
+ json_files = prefecture_code_list.map { "#{DATA_DIR}#{_1}.json" }
34
37
  results = json_files.map do |json_file|
35
- data = JSON.parse(File.open(json_file).read, { symbolize_names: true })
38
+ data = json_data_from(json_file)
36
39
  build_local_gov(data, conditions)
37
40
  end.flatten.compact
38
41
  return nil if results.empty?
@@ -40,6 +43,30 @@ module JpLocalGov
40
43
  results
41
44
  end
42
45
 
46
+ # Inspect code by check digits defined in JISX0402
47
+ # https://www.soumu.go.jp/main_content/000137948.pdf
48
+ def valid_code?(code)
49
+ unless code.is_a?(String) && code.length == VALID_CODE_LENGTH && prefecture_code_list.include?(code[0..1])
50
+ return false
51
+ end
52
+
53
+ sub_total = code.chars
54
+ .take(CHECK_DIGITS_INDEX)
55
+ .map.with_index { |digit, index| digit.to_i * (CHECK_DIGITS_INDEX - index + 1) }
56
+ .sum
57
+ candidate = (CHECK_BASE - sub_total % CHECK_BASE) % 10
58
+ check_digits = sub_total >= CHECK_BASE ? candidate : CHECK_BASE - sub_total
59
+ code[CHECK_DIGITS_INDEX] == check_digits.to_s
60
+ end
61
+
62
+ def all
63
+ json_files = prefecture_code_list.map { "#{DATA_DIR}#{_1}.json" }
64
+ json_files.flat_map do |json_file|
65
+ data = json_data_from(json_file)
66
+ data.values.map { |value| JpLocalGov::LocalGov.new(value) }
67
+ end
68
+ end
69
+
43
70
  def build_local_gov(data, conditions)
44
71
  data.values
45
72
  .select { |target| filter(target, conditions) }
@@ -51,18 +78,14 @@ module JpLocalGov
51
78
  conditions.map { |condition| target[condition[0]] == condition[1] }.all?
52
79
  end
53
80
 
54
- # Inspect code by check digits defined in JISX0402
55
- # https://www.soumu.go.jp/main_content/000137948.pdf
56
- def valid_code?(code)
57
- sub_total = code.chars
58
- .take(CHECK_DIGITS_INDEX)
59
- .map.with_index { |digit, index| digit.to_i * (CHECK_DIGITS_INDEX - index + 1) }
60
- .sum
61
- candidate = (CHECK_BASE - sub_total % CHECK_BASE) % 10
62
- check_digits = sub_total > CHECK_BASE ? candidate : CHECK_BASE - sub_total
63
- code[CHECK_DIGITS_INDEX] == check_digits.to_s
81
+ def prefecture_code_list
82
+ [*PREFECTURE_RANGE].map { format("%02<number>d", number: _1) }
83
+ end
84
+
85
+ def json_data_from(json_file)
86
+ JSON.parse(File.read(json_file), { symbolize_names: true })
64
87
  end
65
88
 
66
- private_class_method :valid_code?, :build_local_gov, :filter
89
+ private_class_method :build_local_gov, :filter, :prefecture_code_list, :json_data_from
67
90
  private_constant :CHECK_DIGITS_INDEX, :CHECK_BASE
68
91
  end
@@ -0,0 +1,9 @@
1
+ module JpLocalGov
2
+ module Random
3
+ DATA_DIR: String
4
+
5
+ RANDOMIZE_TARGET: Array[String]
6
+
7
+ def self?.sample_data: () -> JpLocalGov::LocalGov
8
+ end
9
+ end
data/sig/jp_local_gov.rbs CHANGED
@@ -5,15 +5,25 @@ module JpLocalGov
5
5
 
6
6
  CHECK_BASE: Integer
7
7
 
8
+ PREFECTURE_RANGE: Range[Integer]
9
+
10
+ VALID_CODE_LENGTH: Integer
11
+
8
12
  def self?.included: (Class | Module model_class) -> (Class | Module)
9
13
 
10
14
  def self?.find: (String local_gov_code) -> (nil | JpLocalGov::LocalGov)
11
15
 
12
16
  def self?.where: (Hash[Symbol, untyped] conditions) -> (nil | Array[JpLocalGov::LocalGov])
13
17
 
18
+ def self?.valid_code?: (String code) -> bool
19
+
20
+ def self.all: () -> Array[JpLocalGov::LocalGov]
21
+
14
22
  def self?.build_local_gov: (Hash[Symbol, untyped] data, Hash[Symbol, String] conditions) -> (nil | Array[JpLocalGov::LocalGov])
15
23
 
16
24
  def self?.filter: (Hash[Symbol, untyped] target, Hash[Symbol, String] conditions) -> bool
17
25
 
18
- def self?.valid_code?: (String code) -> bool
26
+ def prefecture_code_list: () -> Array[String]
27
+
28
+ def self?.json_data_from: (String) -> Hash[Symbol, untyped]
19
29
  end
data/tmp/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *
2
+ !.gitignore
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jp_local_gov
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ikuma-t
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-22 00:00:00.000000000 Z
11
+ date: 2022-02-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Convert japan local government code (JIS X 0402 based) into the local
14
14
  government name.
@@ -18,16 +18,20 @@ executables: []
18
18
  extensions: []
19
19
  extra_rdoc_files: []
20
20
  files:
21
+ - ".github/ISSUE_TEMPLATE/bug-report.yml"
22
+ - ".github/ISSUE_TEMPLATE/feature-suggestion.yml"
23
+ - ".github/codespell-problem-matcher.json"
21
24
  - ".github/dependabot.yml"
25
+ - ".github/misspell-problem-matcher.json"
22
26
  - ".github/workflows/auto-update.yml"
23
27
  - ".github/workflows/lint.yml"
24
28
  - ".github/workflows/main.yml"
29
+ - ".github/workflows/spell-checking.yml"
25
30
  - ".github/workflows/steep.yml"
26
31
  - ".github/workflows/test.yml"
27
32
  - ".gitignore"
28
33
  - ".rspec"
29
34
  - ".rubocop.yml"
30
- - ".ruby-version"
31
35
  - Appraisals
32
36
  - CHANGELOG.md
33
37
  - CODE_OF_CONDUCT.md
@@ -40,8 +44,10 @@ files:
40
44
  - bin/generate_rbs
41
45
  - bin/lint
42
46
  - bin/setup
47
+ - bin/spec_runner.rb
43
48
  - bin/steep
44
49
  - bin/test
50
+ - codespell.txt
45
51
  - data/base.rb
46
52
  - data/exporter.rb
47
53
  - data/importer.rb
@@ -99,11 +105,14 @@ files:
99
105
  - lib/jp_local_gov.rb
100
106
  - lib/jp_local_gov/base.rb
101
107
  - lib/jp_local_gov/local_gov.rb
108
+ - lib/jp_local_gov/random.rb
102
109
  - lib/jp_local_gov/version.rb
103
110
  - sig/jp_local_gov.rbs
104
111
  - sig/jp_local_gov/base.rbs
105
112
  - sig/jp_local_gov/local_gov.rbs
113
+ - sig/jp_local_gov/random.rbs
106
114
  - sig/jp_local_gov/version.rbs
115
+ - tmp/.gitignore
107
116
  homepage: https://github.com/IkumaTadokoro/jp_local_gov
108
117
  licenses:
109
118
  - MIT
@@ -116,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
125
  requirements:
117
126
  - - ">="
118
127
  - !ruby/object:Gem::Version
119
- version: 3.0.0
128
+ version: 2.7.0
120
129
  required_rubygems_version: !ruby/object:Gem::Requirement
121
130
  requirements:
122
131
  - - ">="
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 3.0.0