local_gov_code 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +105 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/local_gov_code/local_gov_data.rb +1974 -0
- data/lib/local_gov_code/version.rb +3 -0
- data/lib/local_gov_code.rb +112 -0
- data/local_gov_code.gemspec +25 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e32a02438c316bf7890afb2d59311d2c5513c16e
|
4
|
+
data.tar.gz: efe02c0a1641ae5672dc7dc371dd7cec1c4658fa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 267bb89e651dee196996715b5d0e150244f60e810dcd2f5b82e2fe774f11c3b98ae6d5f98c3cab27755d810fdb19b496e56644808161ac64eebc612251f06419
|
7
|
+
data.tar.gz: 164e80226576f02e3d79b982957038e25ac5306ff1c4ba3d17981d9d4542a48c46242c278ccba6e5e6a1d12866faa128bf30600577d97b907a417f2a7a94e5d3
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Hideo NAKAMURA
|
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,105 @@
|
|
1
|
+
# LocalGovCode
|
2
|
+
|
3
|
+
全国地方公共団体コード(都道府県コード及び市区町村コード)を収録したgem。
|
4
|
+
|
5
|
+
データソースは[総務省HP](http://www.soumu.go.jp/denshijiti/code.html)(平成28年5月21日閲覧)。
|
6
|
+
|
7
|
+
* 都道府県コード及び市区町村コードは平成26年4月5日現在のもの。
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Gemfileに次の1行を加え、
|
12
|
+
|
13
|
+
gem 'local_gov_code'
|
14
|
+
|
15
|
+
その後、bundleでインストール。
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
あるいは、
|
20
|
+
|
21
|
+
$ gem install local_gov_code
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
LocalGovCodeのインスタンスに対して地方自治体コード(5桁)で問い合わせる(findメソッド)ことで、LocalGovインスタンスが得られます。
|
26
|
+
|
27
|
+
また、都道府県名+市区町村名や市区町村名で問い合わせる(find_by_fullname, find_by_nameメソッド)と、LocalGovインスタンスの配列が得られます。
|
28
|
+
|
29
|
+
LocalGovインスタンスからは、市区町村コード、都道府県名、市区町村名、よみなどを取得することが出来ます。
|
30
|
+
|
31
|
+
require 'local_gov_code'
|
32
|
+
|
33
|
+
# new ではなく、 instance メソッドを用います。
|
34
|
+
local_gov_code = LocalGovCode.instance
|
35
|
+
|
36
|
+
# 地方自治体コード(5桁)でLocalGovインスタンスを取得
|
37
|
+
|
38
|
+
lg01000 = local_gov_code.find(1000) # 整数でも可。これは北海道'01000'
|
39
|
+
lg47201 = local_gov_code.find('47201') # 文字列でも可
|
40
|
+
|
41
|
+
# LocalGovインスタンスは、次の情報を持っている。
|
42
|
+
|
43
|
+
lg01000.code # '01000'
|
44
|
+
lg01000.checksum # 0
|
45
|
+
lg01000.fullname # '北海道'
|
46
|
+
lg01000.prefname # '北海道'
|
47
|
+
lg01000.name # ''
|
48
|
+
lg01000.prefkana # 'ホッカイドウ'
|
49
|
+
lg01000.kana # ''
|
50
|
+
|
51
|
+
lg47201.code # '47201'
|
52
|
+
lg47201.checksum # 8
|
53
|
+
lg47201.fullname # '沖縄県那覇市'
|
54
|
+
lg47201.prefname # '沖縄県'
|
55
|
+
lg47201.name # '那覇市'
|
56
|
+
lg47201.prefkana # 'オキナワケン'
|
57
|
+
lg47201.kana # 'ナハシ'
|
58
|
+
|
59
|
+
# 都道府県名+市区町村名だと配列が得られます。
|
60
|
+
# 現在は同一都道府県に同一名称の市区町村は複数ありませんので、
|
61
|
+
# 配列の要素数はすべて1です。
|
62
|
+
|
63
|
+
tokyokitaku = local_gov_code.find_by_fullname('東京都北区').first
|
64
|
+
tokyokitaku.code # '13117'
|
65
|
+
|
66
|
+
# 市区町村名だけでも配列が得られます。
|
67
|
+
|
68
|
+
ikedas = local_gov_code.find_by_name('池田町')
|
69
|
+
ikedas.each do |ikeda|
|
70
|
+
print ikeda.fullname
|
71
|
+
print ' '
|
72
|
+
end
|
73
|
+
# -> 北海道池田町 福井県池田町 長野県池田町 岐阜県池田町
|
74
|
+
|
75
|
+
# 政令市は、政令市名のほか政令市+区名でもデータがあります。
|
76
|
+
# 例えば、3区ある静岡市の場合は、次の4つのデータが存在します。
|
77
|
+
# '22100' 静岡市
|
78
|
+
# '22101' 静岡市葵区
|
79
|
+
# '22102' 静岡市駿河区
|
80
|
+
# '22103' 静岡市清水区
|
81
|
+
|
82
|
+
# find_by_fullname, find_by_nameは `==` のものを検索します。
|
83
|
+
|
84
|
+
# すべての地方公共団体を取得することも出来ます。
|
85
|
+
# LocalGovインスタンスの配列で、コード順に入っています。
|
86
|
+
|
87
|
+
all = local_gov_code.all
|
88
|
+
all.size = 1963
|
89
|
+
all.first.fullname # '北海道'
|
90
|
+
all.last.fullname # '沖縄県与那国町'
|
91
|
+
|
92
|
+
## Development
|
93
|
+
|
94
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
95
|
+
|
96
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
97
|
+
|
98
|
+
## Contributing
|
99
|
+
|
100
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/cxn03651/local_gov_code.
|
101
|
+
|
102
|
+
|
103
|
+
## License
|
104
|
+
|
105
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "local_gov_code"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|