jp_local_gov 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +7 -0
  2. data/.github/dependabot.yml +14 -0
  3. data/.github/workflows/auto-update.yml +27 -0
  4. data/.github/workflows/lint.yml +21 -0
  5. data/.github/workflows/main.yml +16 -0
  6. data/.github/workflows/steep.yml +30 -0
  7. data/.github/workflows/test.yml +20 -0
  8. data/.gitignore +14 -0
  9. data/.rspec +3 -0
  10. data/.rubocop.yml +17 -0
  11. data/.ruby-version +1 -0
  12. data/Appraisals +5 -0
  13. data/CHANGELOG.md +5 -0
  14. data/CODE_OF_CONDUCT.md +84 -0
  15. data/Gemfile +24 -0
  16. data/LICENSE.txt +21 -0
  17. data/README.md +151 -0
  18. data/Rakefile +44 -0
  19. data/Steepfile +6 -0
  20. data/bin/console +15 -0
  21. data/bin/generate_rbs +13 -0
  22. data/bin/lint +3 -0
  23. data/bin/setup +7 -0
  24. data/bin/steep +4 -0
  25. data/bin/test +4 -0
  26. data/data/base.rb +77 -0
  27. data/data/exporter.rb +65 -0
  28. data/data/importer.rb +65 -0
  29. data/data/json/01.json +1757 -0
  30. data/data/json/02.json +362 -0
  31. data/data/json/03.json +299 -0
  32. data/data/json/04.json +362 -0
  33. data/data/json/05.json +227 -0
  34. data/data/json/06.json +317 -0
  35. data/data/json/07.json +533 -0
  36. data/data/json/08.json +398 -0
  37. data/data/json/09.json +227 -0
  38. data/data/json/10.json +317 -0
  39. data/data/json/11.json +659 -0
  40. data/data/json/12.json +542 -0
  41. data/data/json/13.json +560 -0
  42. data/data/json/14.json +551 -0
  43. data/data/json/15.json +344 -0
  44. data/data/json/16.json +137 -0
  45. data/data/json/17.json +173 -0
  46. data/data/json/18.json +155 -0
  47. data/data/json/19.json +245 -0
  48. data/data/json/20.json +695 -0
  49. data/data/json/21.json +380 -0
  50. data/data/json/22.json +407 -0
  51. data/data/json/23.json +632 -0
  52. data/data/json/24.json +263 -0
  53. data/data/json/25.json +173 -0
  54. data/data/json/26.json +335 -0
  55. data/data/json/27.json +668 -0
  56. data/data/json/28.json +452 -0
  57. data/data/json/29.json +353 -0
  58. data/data/json/30.json +272 -0
  59. data/data/json/31.json +173 -0
  60. data/data/json/32.json +173 -0
  61. data/data/json/33.json +281 -0
  62. data/data/json/34.json +281 -0
  63. data/data/json/35.json +173 -0
  64. data/data/json/36.json +218 -0
  65. data/data/json/37.json +155 -0
  66. data/data/json/38.json +182 -0
  67. data/data/json/39.json +308 -0
  68. data/data/json/40.json +668 -0
  69. data/data/json/41.json +182 -0
  70. data/data/json/42.json +191 -0
  71. data/data/json/43.json +452 -0
  72. data/data/json/44.json +164 -0
  73. data/data/json/45.json +236 -0
  74. data/data/json/46.json +389 -0
  75. data/data/json/47.json +371 -0
  76. data/data/prefecture_capital.json +190 -0
  77. data/gemfiles/rails61.gemfile +25 -0
  78. data/gemfiles/rails61.gemfile.lock +127 -0
  79. data/jp_local_gov.gemspec +31 -0
  80. data/lib/jp_local_gov/base.rb +13 -0
  81. data/lib/jp_local_gov/local_gov.rb +17 -0
  82. data/lib/jp_local_gov/version.rb +5 -0
  83. data/lib/jp_local_gov.rb +68 -0
  84. data/sig/jp_local_gov/base.rbs +7 -0
  85. data/sig/jp_local_gov/local_gov.rbs +19 -0
  86. data/sig/jp_local_gov/version.rbs +3 -0
  87. data/sig/jp_local_gov.rbs +19 -0
  88. metadata +130 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4860d4939032f21410e79a628f6000fd037f755e9997903e670e8a9195c272c9
4
+ data.tar.gz: 2f263d1c09e9db4e138fbaac8bd31bc10f26692bf1bd6b2a1ee07a9c4f879578
5
+ SHA512:
6
+ metadata.gz: af1984c55d50f4368dfda951e6cc2a18e4a564e54002da1728b1a5c12baeeaddfe89efd38bd36c759d1ce5ff5966f0870eb7e35e42315b703c112eb056cc599d
7
+ data.tar.gz: ee7b9dc6f8cca9f271a173acac5052a517c9882fb34911f12503782879e29c5239aa3773ea856d5765550b5e8965ad059863f2686e49a36f7200cfa3d18e9c68
@@ -0,0 +1,14 @@
1
+ # To get started with Dependabot version updates, you'll need to specify which
2
+ # package ecosystems to update and where the package manifests are located.
3
+ # Please see the documentation for all configuration options:
4
+ # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5
+
6
+ version: 2
7
+ updates:
8
+ - package-ecosystem: bundler
9
+ directory: "/"
10
+ schedule:
11
+ interval: "daily"
12
+ time: "20:00"
13
+ ignore:
14
+ - dependency-name: activesupport
@@ -0,0 +1,27 @@
1
+ name: auto-update
2
+
3
+ on:
4
+ schedule:
5
+ - cron: '0 0 1 * *'
6
+ workflow_dispatch:
7
+
8
+ jobs:
9
+ update-jplocalgov-data:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - name: Set up Ruby
14
+ uses: ruby/setup-ruby@v1
15
+ with:
16
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
17
+ - name: update jplocalgov data
18
+ run: bundle exec rake jplocalgov:data:update_all
19
+ - name: Create Pull Request
20
+ uses: peter-evans/create-pull-request@v3
21
+ with:
22
+ base: main
23
+ branch: update_jplocalgov_data
24
+ branch-suffix: timestamp
25
+ delete-branch: true
26
+ title: bundle exec rake jplocalgov:data:update_all
27
+ commit-message: bundle exec rake jplocalgov:data:update_all
@@ -0,0 +1,21 @@
1
+ name: Lint
2
+
3
+ on:
4
+ push:
5
+ branches: ["main"]
6
+ pull_request:
7
+ branches: ["main"]
8
+
9
+ jobs:
10
+ lint:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - name: Set up Ruby
16
+ uses: ruby/setup-ruby@v1
17
+ with:
18
+ bundler-cache: true
19
+
20
+ - name: Rubocop
21
+ run: bundle exec rubocop
@@ -0,0 +1,16 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 2.6.6
14
+ bundler-cache: true
15
+ - name: Run the default task
16
+ run: bundle exec rake
@@ -0,0 +1,30 @@
1
+ name: Steep
2
+
3
+ on:
4
+ push:
5
+ branches: ["main"]
6
+ tags: ["**"]
7
+ pull_request:
8
+ branches: ["main"]
9
+
10
+ jobs:
11
+ check:
12
+ runs-on: ubuntu-latest
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - uses: ruby/setup-ruby@v1
16
+ with:
17
+ bundler-cache: true
18
+ - run: bundle exec appraisal install
19
+ - run: |
20
+ bundle exec steep check | ruby -pe 'sub(/^(.+):(\d+):(\d+): (.+)$/, %q{::error file=\1,line=\2,col=\3::\4})'
21
+ shell: bash
22
+ stats:
23
+ runs-on: ubuntu-latest
24
+ steps:
25
+ - uses: actions/checkout@v2
26
+ - uses: ruby/setup-ruby@v1
27
+ with:
28
+ bundler-cache: true
29
+ - run: bundle exec appraisal install
30
+ - run: bundle exec rake steep:stats
@@ -0,0 +1,20 @@
1
+ name: Test
2
+
3
+ on:
4
+ push:
5
+ branches: ["main"]
6
+ pull_request:
7
+ branches: ["main"]
8
+
9
+ jobs:
10
+ lint:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - name: Set up Ruby
16
+ uses: ruby/setup-ruby@v1
17
+ with:
18
+ bundler-cache: true
19
+ - run: bundle exec appraisal install
20
+ - run: bundle exec appraisal rspec
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ vendor/bundle
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+
14
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,17 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.0
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
14
+
15
+ inherit_gem:
16
+ rubocop-fjord:
17
+ - "config/rubocop.yml"
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.0.0
data/Appraisals ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ appraise "rails61" do
4
+ gem "activerecord", "~> 6.1.0"
5
+ end
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2021-11-28
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at tadokorodev@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in jp_local_gov.gemspec
6
+ gemspec
7
+
8
+ gem "rake"
9
+
10
+ group :development do
11
+ gem "activesupport", "~> 6.1" # TODO: To avoid steep dependencies error. Refs: https://github.com/soutaro/steep/issues/466
12
+ gem "appraisal"
13
+ gem "nokogiri"
14
+ gem "pdf-reader"
15
+ gem "rbs"
16
+ gem "rubocop"
17
+ gem "rubocop-fjord"
18
+ gem "sqlite3"
19
+ gem "steep"
20
+ end
21
+
22
+ group :test do
23
+ gem "rspec"
24
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 ikuma-t
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,151 @@
1
+ # JpLocalGov
2
+
3
+ Convert local government code based on JIS X 0402 to local government name in Japan.
4
+ 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
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'jp_local_gov'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle install
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install jp_local_gov
21
+
22
+ ## Usage
23
+
24
+ ### Requirement
25
+
26
+ ```ruby
27
+ require 'jp_local_gov'
28
+ ```
29
+
30
+ ### Search Local Government by Code
31
+
32
+ Provide local government code to search local government's data.
33
+ Only a String can be used for 'code'.
34
+
35
+ ```ruby
36
+ chiyodaku = JpLocalGov.find("131016")
37
+ # => #<JpLocalGov::LocalGov:0x00007fe706a8f148 @code="131016", @prefecture_code="13", @prefecture="東京都", @prefecture_kana="トウキョウト", @city="千代田区", @city_kana="チヨダク", @prefecture_capital=false>
38
+ chiyodaku.code
39
+ # => "131016"
40
+ chiyodaku.prefecture_code
41
+ # => "13"
42
+ chiyodaku.prefecture
43
+ # => "東京都"
44
+ chiyodaku.prefecture_kana
45
+ # => "トウキョウト"
46
+ chiyodaku.city
47
+ # => "千代田区"
48
+ chiyodaku.city_kana
49
+ # => "チヨダク"
50
+ chiyodaku.prefecture_capital
51
+ # => false
52
+ ```
53
+
54
+ About prefecture capital: [List of capitals in Japan \- Wikipedia](https://en.wikipedia.org/wiki/List_of_capitals_in_Japan)
55
+
56
+ ### Filtered Search
57
+
58
+ Use the `where` to enable AND searches with multiple conditions(Hash).
59
+ This search function is an exact match search.
60
+
61
+ ```ruby
62
+ 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>]
64
+ misato.map { "#{_1.prefecture}:#{_1.city}" }
65
+ # => ["秋田県:美郷町", "島根県:美郷町", "宮崎県:美郷町"]
66
+
67
+ JpLocalGov.where(prefecture: "東京都", prefecture_capital: true)
68
+ # => [#<JpLocalGov::LocalGov:0x00007fb1c219e418 @code="131041", @prefecture_code="13", @prefecture="東京都", @prefecture_kana="トウキョウト", @city="新宿区", @city_kana="シンジュクク", @prefecture_capital=true>]
69
+
70
+ JpLocalGov.where(prefecture: "東京")
71
+ # => nil
72
+ # Exact match search. You should specified "東京都" instead of "東京".
73
+ ```
74
+
75
+ The following attributes can be specified for the condition.
76
+
77
+ | Attributes | Type | Examples |
78
+ |--------------------|---------------|----------|
79
+ | code | String | "131016" |
80
+ | prefecture_code | String | "13" |
81
+ | prefecture | String | "東京都" |
82
+ | prefecture_kana | String | "トウキョウト" |
83
+ | city | String | "千代田区" |
84
+ | city_kana | String | "チヨダク" |
85
+ | prefecture_capital | true or false | false |
86
+
87
+ ### Usage on Rails (ActiveRecord)
88
+
89
+ Include JpLocalGov to Model which ActiveRecord::Base inherited.
90
+
91
+ ```ruby
92
+ # app/models/insurrance_fees.rb:
93
+ class Place < ActiveRecord::Base
94
+ # local_gov_code:String
95
+
96
+ include JpLocalGov
97
+ jp_local_gov :local_gov_code
98
+ end
99
+ ```
100
+
101
+ By JpLocalGov included, `local_government` method will be generated:
102
+
103
+ ```ruby
104
+ insurance_fee = InsuranceFee.new
105
+ insurance_fee.local_gov_code = "131016"
106
+ insurance_fee.local_government.city
107
+ # => "千代田区"
108
+ ```
109
+
110
+ In Migration file, set `local_gov_code` column type to `string`.
111
+
112
+ ```ruby
113
+ class AddLocalGovCodeToinsuranceFees < ActiveRecord::Migration
114
+ def change
115
+ add_column :insurance_fees, :local_gov_code, :string
116
+ end
117
+ end
118
+ ```
119
+
120
+ ## Development
121
+
122
+ ### Steps
123
+
124
+ 1. Fork it -> `git clone https://github.com/IkumaTadokoro/jp_local_gov/fork`
125
+ 2. Run `bin/setup` to install dependencies
126
+ 3. Create your feature branch
127
+ 4. Implement feature and run `bin/test`, `bin/lint`, `bin/steep` to check your implementation
128
+ 5. Push to the branch
129
+ 6. Create a new Pull Request
130
+
131
+ ### Commands
132
+
133
+ | Command | Details |
134
+ |--------------------|----------------------------------------------------------------------------------------------------------|
135
+ | `bin/console` | An interactive prompt that will allow you to experiment |
136
+ | `bin/generate_rbs` | Create rbs file in `/sig` for new ruby files in `/lib` |
137
+ | `bin/test` | Run `rspec` via Appraisal. <br>To specify the version, use `bin/test <version>`(e.g. `bin/test rails61`) |
138
+ | `bin/lint` | Run Rubocop |
139
+ | `bin/steep` | Run `steep stats` and `steep check` |
140
+
141
+ ## Contributing
142
+
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).
144
+
145
+ ## License
146
+
147
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
148
+
149
+ ## Code of Conduct
150
+
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).
data/Rakefile ADDED
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
13
+
14
+ require_relative "data/importer"
15
+ require_relative "data/exporter"
16
+
17
+ namespace :jplocalgov do
18
+ namespace :data do
19
+ desc "Updates local_government_code data"
20
+ task :update_all do
21
+ puts "Reset temp DB..."
22
+ importer = JpLocalGov::Data::Importer.new
23
+ importer.reset_table
24
+
25
+ puts "Retrieving local government data..."
26
+ importer.retrieve_and_save
27
+
28
+ puts "Extract to json files..."
29
+ JpLocalGov::Data::Exporter.new.execute
30
+ end
31
+ end
32
+ end
33
+
34
+ namespace :steep do
35
+ desc "Run type-check by Steep"
36
+ task :check do
37
+ sh "bundle", "exec", "steep", "check", "--log-level=fatal"
38
+ end
39
+
40
+ desc "Show the Steep coverage report"
41
+ task :stats do
42
+ sh "bundle", "exec", "steep", "stats", "--log-level=fatal", "--format=table"
43
+ end
44
+ end
data/Steepfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ target :lib do
4
+ check "lib"
5
+ signature "sig"
6
+ end
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "jp_local_gov"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/generate_rbs ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "pathname"
5
+
6
+ Dir.glob("lib/**/*.rb") do |rb_file|
7
+ rbs_file = rb_file.sub(/lib/, "sig").sub(/\.rb$/, ".rbs")
8
+ next if File.exist?(rbs_file)
9
+
10
+ Pathname(rbs_file).parent.mkpath
11
+ system "bundle exec rbs prototype rb #{rb_file} > #{rbs_file}", exception: true
12
+ puts "#{rbs_file} generated."
13
+ end
data/bin/lint ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bash
2
+
3
+ bundle exec rubocop -a
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+ bundle exec appraisal install
data/bin/steep ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env bash
2
+
3
+ bundle exec rake steep:stats
4
+ bundle exec rake steep:check
data/bin/test ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env bash
2
+
3
+ appraisal_name=$1
4
+ bundle exec appraisal ${appraisal_name:+ "${appraisal_name}"} rspec
data/data/base.rb ADDED
@@ -0,0 +1,77 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "sqlite3"
4
+
5
+ module JpLocalGov
6
+ module Data
7
+ class Base
8
+ def db
9
+ @db ||= SQLite3::Database.new("tmp/test.db")
10
+ end
11
+
12
+ def reset_table
13
+ drop_table
14
+ create_table
15
+ end
16
+
17
+ def drop_table
18
+ db.execute <<-SQL
19
+ DROP TABLE IF EXISTS local_governments;
20
+ SQL
21
+ end
22
+
23
+ def create_table
24
+ db.execute <<-SQL
25
+ CREATE TABLE local_governments (
26
+ code VARCHAR(5),
27
+ prefecture_code VARCHAR(2),
28
+ prefecture VARCHAR(256),
29
+ prefecture_kana VARCHAR(256),
30
+ city VARCHAR(256),
31
+ city_kana VARCHAR(256),
32
+ prefecture_capital VARCHAR(10)
33
+ );
34
+ SQL
35
+
36
+ db.execute <<-SQL
37
+ CREATE INDEX idx_local_governments ON local_governments (prefecture, city);
38
+ SQL
39
+ end
40
+
41
+ def retrieve_and_save
42
+ db.execute "BEGIN TRANSACTION"
43
+ retrieve.each do |hash|
44
+ insert(hash)
45
+ end
46
+ db.execute "COMMIT"
47
+ end
48
+
49
+ INSERT_SQL = <<-SQL
50
+ INSERT INTO local_governments (
51
+ code,
52
+ prefecture_code,
53
+ prefecture,
54
+ prefecture_kana,
55
+ city,
56
+ city_kana,
57
+ prefecture_capital
58
+ ) VALUES (?, ?, ?, ?, ?, ?, ?);
59
+ SQL
60
+
61
+ private
62
+
63
+ def insert(hash)
64
+ db.execute(
65
+ INSERT_SQL,
66
+ hash[:code],
67
+ hash[:prefecture_code],
68
+ hash[:prefecture],
69
+ hash[:prefecture_kana],
70
+ hash[:city],
71
+ hash[:city_kana],
72
+ hash[:prefecture_capital]
73
+ )
74
+ end
75
+ end
76
+ end
77
+ end