kamome 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.rubocop.yml +25 -0
- data/.travis.yml +12 -0
- data/.yardopts +3 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +72 -0
- data/LICENSE +21 -0
- data/Makefile +12 -0
- data/README.md +139 -0
- data/Rakefile +6 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/kamome.gemspec +47 -0
- data/lib/kamome.rb +74 -0
- data/lib/kamome/configuration.rb +20 -0
- data/lib/kamome/csv_handler.rb +45 -0
- data/lib/kamome/downloader.rb +56 -0
- data/lib/kamome/loader.rb +36 -0
- data/lib/kamome/models/address.rb +83 -0
- data/lib/kamome/models/general.rb +107 -0
- data/lib/kamome/models/jigyosho.rb +106 -0
- data/lib/kamome/operation.rb +79 -0
- data/lib/kamome/transformations/cleaner.rb +19 -0
- data/lib/kamome/transformations/extractor.rb +18 -0
- data/lib/kamome/transformations/general_csv.rb +74 -0
- data/lib/kamome/transformations/jigyosho_csv.rb +81 -0
- data/lib/kamome/version.rb +5 -0
- metadata +188 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: eabc3d7c8fab14f88254defa7d52769a9d674951c3af50f5332e1f5af678fa77
|
4
|
+
data.tar.gz: ae51e66cd3b662dc93ea8cd31223281004db1b097acb07bb07c123d8e0a8ab00
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f354384ca83990e9eddf6367c7d4453bff84729067a137aa1ebae59398f8d4dae94e1a21657e9830ba8289d8d671caec13314ec27235b0db935c95a1c90d2572
|
7
|
+
data.tar.gz: 705d96a73c879e96c18fa7afc6e186913fab28308bf9e4f560d39d25f564712302e1af941382468786a1b42f2b10bda2f7f8043f9b824898efc17f12bec18424
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require: rubocop-rspec
|
2
|
+
AllCops:
|
3
|
+
TargetRubyVersion: 2.5
|
4
|
+
Include:
|
5
|
+
- 'lib/**/*.rb'
|
6
|
+
- 'spec/**/*.rb'
|
7
|
+
|
8
|
+
Metrics/BlockLength:
|
9
|
+
Exclude:
|
10
|
+
- 'spec/**/*_spec.rb'
|
11
|
+
|
12
|
+
Metrics/MethodLength:
|
13
|
+
Max: 20
|
14
|
+
|
15
|
+
Style/AsciiComments:
|
16
|
+
Enabled: false
|
17
|
+
|
18
|
+
Style/Documentation:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
Metrics/LineLength:
|
22
|
+
Max: 120
|
23
|
+
|
24
|
+
RSpec/NestedGroups:
|
25
|
+
Max: 4
|
data/.travis.yml
ADDED
data/.yardopts
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
kamome (0.1.0)
|
5
|
+
rubyzip (~> 1.2)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.5.2)
|
11
|
+
public_suffix (>= 2.0.2, < 4.0)
|
12
|
+
ast (2.4.0)
|
13
|
+
crack (0.4.3)
|
14
|
+
safe_yaml (~> 1.0.0)
|
15
|
+
diff-lcs (1.3)
|
16
|
+
hashdiff (0.3.7)
|
17
|
+
jaro_winkler (1.5.1)
|
18
|
+
parallel (1.12.1)
|
19
|
+
parser (2.5.3.0)
|
20
|
+
ast (~> 2.4.0)
|
21
|
+
powerpack (0.1.2)
|
22
|
+
public_suffix (3.0.3)
|
23
|
+
rainbow (3.0.0)
|
24
|
+
rake (10.5.0)
|
25
|
+
rspec (3.8.0)
|
26
|
+
rspec-core (~> 3.8.0)
|
27
|
+
rspec-expectations (~> 3.8.0)
|
28
|
+
rspec-mocks (~> 3.8.0)
|
29
|
+
rspec-core (3.8.0)
|
30
|
+
rspec-support (~> 3.8.0)
|
31
|
+
rspec-expectations (3.8.2)
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
33
|
+
rspec-support (~> 3.8.0)
|
34
|
+
rspec-mocks (3.8.0)
|
35
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
36
|
+
rspec-support (~> 3.8.0)
|
37
|
+
rspec-support (3.8.0)
|
38
|
+
rubocop (0.60.0)
|
39
|
+
jaro_winkler (~> 1.5.1)
|
40
|
+
parallel (~> 1.10)
|
41
|
+
parser (>= 2.5, != 2.5.1.1)
|
42
|
+
powerpack (~> 0.1)
|
43
|
+
rainbow (>= 2.2.2, < 4.0)
|
44
|
+
ruby-progressbar (~> 1.7)
|
45
|
+
unicode-display_width (~> 1.4.0)
|
46
|
+
rubocop-rspec (1.30.1)
|
47
|
+
rubocop (>= 0.60.0)
|
48
|
+
ruby-progressbar (1.10.0)
|
49
|
+
rubyzip (1.2.2)
|
50
|
+
safe_yaml (1.0.4)
|
51
|
+
unicode-display_width (1.4.0)
|
52
|
+
vcr (4.0.0)
|
53
|
+
webmock (3.4.2)
|
54
|
+
addressable (>= 2.3.6)
|
55
|
+
crack (>= 0.3.2)
|
56
|
+
hashdiff
|
57
|
+
|
58
|
+
PLATFORMS
|
59
|
+
ruby
|
60
|
+
|
61
|
+
DEPENDENCIES
|
62
|
+
bundler (~> 1.17)
|
63
|
+
kamome!
|
64
|
+
rake (~> 10.0)
|
65
|
+
rspec (~> 3.0)
|
66
|
+
rubocop (~> 0.60)
|
67
|
+
rubocop-rspec (~> 1.30)
|
68
|
+
vcr (~> 4.0)
|
69
|
+
webmock (~> 3.4)
|
70
|
+
|
71
|
+
BUNDLED WITH
|
72
|
+
1.17.1
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 kengos.jp Inc. http://github.com/kengos/kamome
|
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/Makefile
ADDED
data/README.md
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
# Kamome
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/kengos/kamome.svg?branch=master)](https://travis-ci.org/kengos/kamome)
|
4
|
+
|
5
|
+
日本郵便の郵便番号データの取得を行うインターフェースです
|
6
|
+
|
7
|
+
以下のように block を渡すことで 郵便番号データ の取り込みで任意の実装を行うことができます
|
8
|
+
|
9
|
+
```rb
|
10
|
+
Kamome.import_general_all do |model, lineno|
|
11
|
+
puts "#{lineno}: #{model.zipcode} => #{model.prefecture}#{model.city}#{model.town}"
|
12
|
+
end
|
13
|
+
```
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'kamome'
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install kamome
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
### 全国一括の郵便番号データの取り込み
|
34
|
+
|
35
|
+
```rb
|
36
|
+
Kamome.import_general_all do |model, lineno|
|
37
|
+
puts "#{lineno}: #{model.zipcode} => #{model.prefecture}#{model.city}#{model.town}"
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
41
|
+
### 全国一括の郵便番号データの取り込み(差分)
|
42
|
+
|
43
|
+
```rb
|
44
|
+
date = Time.local(2018, 11) # 2018/11 更新分の取り込み
|
45
|
+
Kamome.import_general_diff(date: date) do |model, lineno|
|
46
|
+
if model.changed?
|
47
|
+
puts "追加データ: #{model.zipcode} => #{model.prefecture}#{model.city}#{model.town}"
|
48
|
+
else
|
49
|
+
puts "削除データ: #{model.zipcode} => #{model.prefecture}#{model.city}#{model.town}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
```
|
53
|
+
|
54
|
+
### 事業所の郵便番号データの取り込み
|
55
|
+
|
56
|
+
```rb
|
57
|
+
Kamome.import_jigyosho_all do |model, lineno|
|
58
|
+
puts "#{lineno}: #{model.zipcode} => #{model.prefecture}#{model.city}#{model.town}"
|
59
|
+
end
|
60
|
+
```
|
61
|
+
|
62
|
+
### 事業所の郵便番号データの取り込み(差分)
|
63
|
+
|
64
|
+
```rb
|
65
|
+
date = Time.local(2018, 11) # 2018/11 更新分の取り込み
|
66
|
+
Kamome.import_jigyosho_diff(date: date) do |model, lineno|
|
67
|
+
if model.changed?
|
68
|
+
puts "追加データ: #{model.zipcode} => #{model.prefecture}#{model.city}#{model.town}"
|
69
|
+
else
|
70
|
+
puts "削除データ: #{model.zipcode} => #{model.prefecture}#{model.city}#{model.town}"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
## FAQ
|
76
|
+
|
77
|
+
### `Kamome.import_xxx` の model の型を変換したい
|
78
|
+
|
79
|
+
#### Hash にする場合
|
80
|
+
|
81
|
+
```rb
|
82
|
+
Kamome.import_general_all(type: :hash or Kamome::Operation::TYPE_HASH)
|
83
|
+
```
|
84
|
+
|
85
|
+
#### DetailModel にする場合
|
86
|
+
|
87
|
+
```rb
|
88
|
+
Kamome.import_general_all(type: :detail or Kamome::Operation::TYPE_DETAIL)
|
89
|
+
# 通常の戻りの型である `Kamome::Models::Address` ではなく以下のモデルで返却されます
|
90
|
+
# 事業所CSV の場合 `Kamome::Models::Jigyosho`
|
91
|
+
# 通常のCSV の場合 `Kamome::Models::General`
|
92
|
+
```
|
93
|
+
|
94
|
+
## データのクリーニングについて
|
95
|
+
|
96
|
+
### 通常のCSV
|
97
|
+
|
98
|
+
#### `Kamome::Models::General#town` or `Kamome::Models::Address#town`
|
99
|
+
|
100
|
+
|元データ|変換後|備考|
|
101
|
+
|--------|------|----|
|
102
|
+
|以下に掲載がない場合||空白になります|
|
103
|
+
|XXXXXの次に番地がくる場合||空白になります|
|
104
|
+
|XXXXX(YYYY階)|XXXXX(YYYY階)|元の値を維持しています|
|
105
|
+
|XXXXX(YYYYY)|XXXXX|() の部分が除去されます|
|
106
|
+
|
107
|
+
#### `Kamome::Models::General#town_kana`
|
108
|
+
|
109
|
+
|元データ|変換後|備考|
|
110
|
+
|--------|------|----|
|
111
|
+
|イカニケイサイガナイバアイ||空白になります|
|
112
|
+
|XXXXXノツギニバンチガクルバアイ||空白になります|
|
113
|
+
|XXXXX(Yカイ)|XXXXX(Yカイ)|元の値を維持しています|
|
114
|
+
|XXXXX(YYYYY)|XXXXX|() の部分が除去されます|
|
115
|
+
|
116
|
+
### 事業所CSV
|
117
|
+
|
118
|
+
#### 私書箱情報について
|
119
|
+
|
120
|
+
`Kamome::Models::General#post_office_box` or `Kamome::Models::Address#post_office_box`
|
121
|
+
|
122
|
+
`0丁目0番地(ああああ郵便局私書箱第000号)` のようなデータが有った場合
|
123
|
+
|
124
|
+
* post_office_box ... `ああああ郵便局私書箱第000号`
|
125
|
+
* street ... `0丁目0番地`
|
126
|
+
|
127
|
+
として設定されます
|
128
|
+
|
129
|
+
#### `Kamome::Models::General#town_kana`
|
130
|
+
|
131
|
+
## Development
|
132
|
+
|
133
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `make` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
134
|
+
|
135
|
+
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).
|
136
|
+
|
137
|
+
## Contributing
|
138
|
+
|
139
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kengos/kamome.
|
data/Rakefile
ADDED
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 'kamome'
|
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/setup
ADDED
data/kamome.gemspec
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "kamome/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "kamome"
|
8
|
+
spec.version = Kamome::VERSION
|
9
|
+
spec.authors = ["kengos"]
|
10
|
+
spec.email = ["kengo@kengos.jp"]
|
11
|
+
|
12
|
+
spec.summary = "kamome-#{Kamome::VERSION}"
|
13
|
+
spec.description = %q{the Japanese postcode loading interface}
|
14
|
+
spec.homepage = "https://github.com/kengos/kamome"
|
15
|
+
spec.licenses = ['MIT']
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
|
22
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
23
|
+
spec.metadata["source_code_uri"] = "https://github.com/kengos/kamome"
|
24
|
+
spec.metadata["changelog_uri"] = "https://github.com/kengos/kamome/blob/master/CHANGELOG.md"
|
25
|
+
else
|
26
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
27
|
+
"public gem pushes."
|
28
|
+
end
|
29
|
+
|
30
|
+
# Specify which files should be added to the gem when it is released.
|
31
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
32
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
33
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
34
|
+
end
|
35
|
+
spec.bindir = "exe"
|
36
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
37
|
+
spec.require_paths = ["lib"]
|
38
|
+
|
39
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
40
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
41
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
42
|
+
spec.add_development_dependency 'vcr', '~> 4.0'
|
43
|
+
spec.add_development_dependency 'webmock', '~> 3.4'
|
44
|
+
spec.add_development_dependency 'rubocop', '~> 0.60'
|
45
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 1.30'
|
46
|
+
spec.add_dependency 'rubyzip', '~> 1.2'
|
47
|
+
end
|
data/lib/kamome.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'kamome/version'
|
4
|
+
require 'kamome/configuration'
|
5
|
+
require 'kamome/loader'
|
6
|
+
require 'kamome/operation'
|
7
|
+
|
8
|
+
module Kamome
|
9
|
+
class Error < StandardError; end
|
10
|
+
class ArgumentError < StandardError; end
|
11
|
+
class DownloadError < Error; end
|
12
|
+
|
13
|
+
class << self
|
14
|
+
def configure
|
15
|
+
yield(configuration)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Import ken_all.zip
|
19
|
+
# @param [Symbol] type :default, :hash, :detail
|
20
|
+
# @example
|
21
|
+
# Kamome.import_general_all do |model, lineno|
|
22
|
+
# # do something
|
23
|
+
# end
|
24
|
+
def import_general_all(type: Operation::TYPE_DEFAULT, &block)
|
25
|
+
operation = ::Kamome::Operation.general_all(type: type)
|
26
|
+
loader.call(operation: operation, &block)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Import add_yymm.zip and del_yymm.zip
|
30
|
+
# @param [Time] date
|
31
|
+
# @param [Symbol] type :default, :hash, :detail
|
32
|
+
# @example
|
33
|
+
# Kamome.import_general_diff do |model, lineno|
|
34
|
+
# # do something
|
35
|
+
# end
|
36
|
+
def import_general_diff(date:, type: Operation::TYPE_DEFAULT, &block)
|
37
|
+
operation = ::Kamome::Operation.general_diff(date: date, type: type)
|
38
|
+
loader.call(operation: operation, &block)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Import jigyosyo.zip
|
42
|
+
# @param [Symbol] type :default, :hash, :detail
|
43
|
+
# @example
|
44
|
+
# Kamome.import_jigyosho_all do |model, lineno|
|
45
|
+
# # do something
|
46
|
+
# end
|
47
|
+
def import_jigyosho_all(type: Operation::TYPE_DEFAULT, &block)
|
48
|
+
operation = ::Kamome::Operation.jigyosho_all(type: type)
|
49
|
+
loader.call(operation: operation, &block)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Import jadd#{yymm}.zip and jdel#{yymm}.zip
|
53
|
+
# @param [Time] date
|
54
|
+
# @param [Symbol] type :default, :hash, :detail
|
55
|
+
# @example
|
56
|
+
# Kamome.import_jigyosho_all do |model, lineno|
|
57
|
+
# # do something
|
58
|
+
# end
|
59
|
+
def import_jigyosho_diff(date:, type: Operation::TYPE_DEFAULT, &block)
|
60
|
+
operation = ::Kamome::Operation.jigyosho_diff(date: date, type: type)
|
61
|
+
loader.call(operation: operation, &block)
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def configuration
|
67
|
+
@configuration ||= Kamome::Configuration.new
|
68
|
+
end
|
69
|
+
|
70
|
+
def loader
|
71
|
+
Kamome::Loader.new(config: configuration)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|