japanese_local_governments 0.1.0 → 0.2.0
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 +4 -4
- data/README.md +13 -3
- data/exe/jlg +0 -0
- data/japanese_local_governments.gemspec +3 -2
- data/lib/japanese_local_governments/cli.rb +7 -3
- data/lib/japanese_local_governments/governments.rb +8 -5
- data/lib/japanese_local_governments/prefectures.rb +3 -2
- data/lib/japanese_local_governments/version.rb +1 -1
- data/lib/jlg.rb +4 -2
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 296452bdc7cfb44abca1d1cbe79ec18efde15bc8
|
4
|
+
data.tar.gz: 28a6efb56dab46ef8a0670ada1570e5f73c6d609
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c516f1dc21ffb3c0415f4dbc6adbb78fd3fef5a1358d4275b897433bc09780dc4c21a16de94bee2ccd3c3825a425f6fded2b7f650a4493f4e5d89cd22bb8a41
|
7
|
+
data.tar.gz: fc66edbb255152041d92bb13afef6e4452cee9322f75d56283cac9772c12cd2aff76732fd084f517b86cf1f12b0fec33efdad8652ac425a41ce7f1132577fbf8
|
data/README.md
CHANGED
@@ -10,6 +10,10 @@
|
|
10
10
|
|
11
11
|
これらの機能をライブラリとして提供するとともに、コマンドラインツールとしても利用できます。
|
12
12
|
|
13
|
+
次のコマンドで本ツールの持つ地方自治体のデータがすべて出力されます。
|
14
|
+
|
15
|
+
$ jlg list
|
16
|
+
|
13
17
|
## Installation
|
14
18
|
|
15
19
|
Add this line to your application's Gemfile:
|
@@ -73,6 +77,7 @@ jlg は次のサブコマンドを持ちます。
|
|
73
77
|
|
74
78
|
`-o` オプションを利用すると、指定したファイルに結果を出力します。
|
75
79
|
`-p` オプションを利用すると、都道府県のみのデータを出力します。
|
80
|
+
`-s` オプションを利用すると ShiftJISでファイルを出力します。(`-o` オプションと同時に使った場合のみ有効)
|
76
81
|
|
77
82
|
#### 使用例
|
78
83
|
$ jlg list
|
@@ -91,7 +96,7 @@ jlg は次のサブコマンドを持ちます。
|
|
91
96
|
### add_code
|
92
97
|
都道府県名、自治体名を表すカラムを持つCSVファイルに 自治体コードをカラムを追加します。
|
93
98
|
入力ファイルとしては次のようなファイルを用意します。
|
94
|
-
1
|
99
|
+
1行目はカラムヘッダである必要があります。デフォルトでは pref を都道府県名を表すカラム、name を自治体名を表すカラムとして処理します。
|
95
100
|
|
96
101
|
pref,name,type,district,furigana
|
97
102
|
北海道,北海道,都道府県,北海道地方,ほっかいどう
|
@@ -107,12 +112,17 @@ jlg は次のサブコマンドを持ちます。
|
|
107
112
|
011011,北海道,札幌市中央区,行政区,北海道地方,さっぽろしちゅうおうく
|
108
113
|
011029,北海道,札幌市北区,行政区,北海道地方,さっぽろしきたく
|
109
114
|
|
110
|
-
`-o`
|
111
|
-
|
115
|
+
`-o` オプションを利用すると、出力ファイル名を指定することができます。このオプションがない場合、入力ファイル名に実行日付が付加されたファイル名で出力します。
|
116
|
+
`-p`,`-n` オプションを利用すると都道府県名と自治体名を表すカラム名を指定することができます。
|
117
|
+
`-s` オプションを利用するとShiftJISで作成されたCSVファイルを処理できます。
|
112
118
|
#### 使用例
|
113
119
|
$ jlg add_code 自治体データ.csv #=> 自治体データ_20160207.csv という名前のファイルに出力される
|
114
120
|
|
115
121
|
$ jlg add_code 自治体データ.csv -o 自治体データ_コード付き.csv #=> 自治体データ_コード付き.csv という名前のファイルに出力される
|
122
|
+
|
123
|
+
$ jlg add_code 自治体データ.csv -o 自治体データ_コード付き.csv -p 都道府県 -n 自治体名 #=> 自治体データ_コード付き.csv という名前のファイルに出力される。都道府県、自治体名のカラム名を指定しています。
|
124
|
+
|
125
|
+
$ jlg add_code 自治体データ_sjis.csv -s #=> ShiftJISで作成されたCSVファイル 自治体データ_sjis.csv を読み込んで ShiftJIS で出力します。
|
116
126
|
|
117
127
|
### help
|
118
128
|
$ jlg help [COMMAND] # Describe available commands or one specific command
|
data/exe/jlg
CHANGED
File without changes
|
@@ -6,12 +6,13 @@ require 'japanese_local_governments/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "japanese_local_governments"
|
8
8
|
spec.version = JLG::VERSION
|
9
|
-
spec.authors = ["
|
10
|
-
spec.email = ["
|
9
|
+
spec.authors = ["HeRoMo"]
|
10
|
+
spec.email = ["dev@asterisk-works.jp"]
|
11
11
|
|
12
12
|
spec.summary = %q{A Utility of Japanese local governments data}
|
13
13
|
spec.description = %q{Utility of Japanese local governments data}
|
14
14
|
spec.homepage = "https://github.com/HeRoMo/japanese_local_governments"
|
15
|
+
spec.required_ruby_version = '>= 2.1.0'
|
15
16
|
|
16
17
|
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
17
18
|
# delete this section to allow pushing this gem to any host.
|
@@ -7,13 +7,14 @@ module JLG
|
|
7
7
|
class CLI < Thor
|
8
8
|
desc "list","Output local governments by CSV format"
|
9
9
|
method_option :prefectures, type: :boolean, aliases:'-p', required:false, desc: "output only prefecures"
|
10
|
+
method_option :sjis, type: :boolean, aliases:'-s', required:false, desc: "output sjis encoding(file output only)"
|
10
11
|
method_option :output, type: :string, aliases:'-o', required:false, desc: "output filepath"
|
11
12
|
def list
|
12
13
|
pref_only = options[:prefectures]
|
13
14
|
if pref_only
|
14
|
-
JLG::Prefectures.list(options[:output])
|
15
|
+
JLG::Prefectures.list(options[:output],sjis:options[:sjis])
|
15
16
|
else
|
16
|
-
JLG::Governments.list(options[:output])
|
17
|
+
JLG::Governments.list(options[:output],sjis:options[:sjis])
|
17
18
|
end
|
18
19
|
rescue =>e
|
19
20
|
$stderr.puts e.message
|
@@ -33,8 +34,11 @@ module JLG
|
|
33
34
|
|
34
35
|
desc "add_code INPUT_FILE", "Read CSV file, Output append local government code"
|
35
36
|
method_option :output, type: :string, aliases:'-o', required:false, desc: 'output filepath'
|
37
|
+
method_option :pref_column, type: :string, aliases:'-p', require:false, default:'pref',desc: 'set prefecure column name'
|
38
|
+
method_option :name_column, type: :string, aliases:'-n', require:false, default:'name',desc: 'set name column name'
|
39
|
+
method_option :sjis, type: :boolean, aliases:'-s', require:false, default:false, desc: 'input/output in sjis.(default: UTF-8)'
|
36
40
|
def add_code(input_file)
|
37
|
-
JLG::Governments.append_code(input_file, options[:output])
|
41
|
+
JLG::Governments.append_code(input_file, options[:output], pref:options[:pref_column], name:options[:name_column], sjis:options[:sjis])
|
38
42
|
rescue =>e
|
39
43
|
$stderr.puts e.message
|
40
44
|
end
|
@@ -8,8 +8,9 @@ module JLG
|
|
8
8
|
|
9
9
|
# 地方自治体のリストを出力する
|
10
10
|
# @param filename [String] 出力ファイルのパス
|
11
|
-
|
12
|
-
|
11
|
+
# @param sjis [Boolean] Shift_JISで出力する場合に true とする
|
12
|
+
def self.list(filename=nil,sjis:false)
|
13
|
+
JLG.list(filename,sjis:sjis){|out|
|
13
14
|
out.puts HEADER.join(',')
|
14
15
|
GOV_DATA.values.each do |data|
|
15
16
|
out.puts data.values.join(',')
|
@@ -38,13 +39,15 @@ module JLG
|
|
38
39
|
# @param outputfile [String] 出力ファイル名。
|
39
40
|
# @param pref [String] 都道府県カラムの名前
|
40
41
|
# @param name [String] 自治体名カラムの名前
|
41
|
-
|
42
|
+
# @param sjis [Boolean] 処理したいファイルがShift_JISの場合、trueをセット。デフォルトはfalseでUTF-8として処理する
|
43
|
+
def self.append_code(inputfile, outputfile=nil, pref:'pref', name: 'name',sjis:false)
|
44
|
+
encode = (sjis) ? 'Shift_JIS':'UTF-8'
|
42
45
|
if outputfile.nil?
|
43
46
|
date = Date.today.strftime('%Y%m%d')
|
44
47
|
outputfile = './' + File.basename(inputfile,'.*') + "_#{date}.csv"
|
45
48
|
end
|
46
|
-
CSV.open(inputfile,headers: true,return_headers:true) do|csv|
|
47
|
-
CSV.open(outputfile,"wb") do |out|
|
49
|
+
CSV.open(inputfile,"r:#{encode}:UTF-8",headers: true,return_headers:true) do|csv|
|
50
|
+
CSV.open(outputfile,"wb:#{encode}") do |out|
|
48
51
|
csv.each do |row|
|
49
52
|
if row.header_row?
|
50
53
|
out<<row.headers.to_a.insert(0,'code')
|
@@ -6,8 +6,9 @@ module JLG
|
|
6
6
|
|
7
7
|
# 都道府県リストを出力する
|
8
8
|
# @param filename [String] 出力先ファイルのパス
|
9
|
-
|
10
|
-
|
9
|
+
# @param sjis [Boolean] Shift_JISで出力する場合に true とする
|
10
|
+
def self.list(filename=nil,sjis:false)
|
11
|
+
JLG.list(filename,sjis:sjis){|out|
|
11
12
|
out.puts HEADER.join(',')
|
12
13
|
GOV_DATA_NAME_INDEX.each do |key,value|
|
13
14
|
out.puts GOV_DATA[value[key]].values.join(',')
|
data/lib/jlg.rb
CHANGED
@@ -4,10 +4,12 @@ require 'japanese_local_governments/cli'
|
|
4
4
|
module JLG
|
5
5
|
# 指定されたファイル、または標準出力に結果を出力する
|
6
6
|
# @param filename [String] 出力先のファイル名。nilの場合は標準出力に出力する
|
7
|
+
# @param sjis [Boolean] ファイル出力する場合にShiftJISで出力するかどうかを指定する
|
7
8
|
# @yield [out] 結果を出力する処理を実装する
|
8
9
|
# @yieldparam out [IO] 出力先のIOオブジェクト。
|
9
|
-
def self.list(filename=nil)
|
10
|
-
|
10
|
+
def self.list(filename=nil, sjis:false)
|
11
|
+
encode = sjis ? 'Shift_JIS':'UTF-8'
|
12
|
+
out = filename.nil? ? $stdout : open(filename, "wb:#{encode}")
|
11
13
|
yield(out)
|
12
14
|
rescue =>e
|
13
15
|
raise e
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: japanese_local_governments
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- HeRoMo
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
@@ -124,7 +124,7 @@ dependencies:
|
|
124
124
|
version: 0.8.0
|
125
125
|
description: Utility of Japanese local governments data
|
126
126
|
email:
|
127
|
-
-
|
127
|
+
- dev@asterisk-works.jp
|
128
128
|
executables:
|
129
129
|
- jlg
|
130
130
|
extensions: []
|
@@ -157,7 +157,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
157
157
|
requirements:
|
158
158
|
- - ">="
|
159
159
|
- !ruby/object:Gem::Version
|
160
|
-
version:
|
160
|
+
version: 2.1.0
|
161
161
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
162
|
requirements:
|
163
163
|
- - ">="
|