kamome 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 580db2ebe5e52ce51d8014ad886247ef89ae3ab9f8bccb82397a3c3ce0a15e75
4
- data.tar.gz: 0605ca8f9f680d15fb87b2396e4f8db0930a8d3984ee18eaa5b3b95d51ec9a8b
3
+ metadata.gz: 35ffe91d4c66bc1f179e7db9980ecbf6800633de1af8f3de76645dffb926d423
4
+ data.tar.gz: 5e373d056502af1d4f6b1ca51d0ca44d2adf26daaef07d706e79ca115472fd9a
5
5
  SHA512:
6
- metadata.gz: 6a2cd80afb342ff0ca2f68ff769a6f11b478dc06e5514d836142763102cff983a9760fa9bea9334d59fd76744a09c766a727cad3a5f79e52719a5c89330b9fa1
7
- data.tar.gz: 2e17669f0e652e42ba98f8429ca034d5d770b0b7ba5bd5e0380402b05a7ad7d7d3883aa3c57738cbb638e376722eef40e656fc9f56d92f2e0ce98aa9318194e2
6
+ metadata.gz: 4b41f5d5424612e149377fd3deff5b29e5cfe5e88addca51f89c49deeabe3a0e50111686a429f1ce0b314239fe5508222fc06f8277fd5adb10095961c8bc9c52
7
+ data.tar.gz: 759139eb2ce52cd217b576f814fae768e78af52f330a6d78bafee4502270157a34e1a058e438411a227bfd8035276b16ac9a2ce1ee80f6540a67bb8faa6d6c5d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelogs
2
2
 
3
- ## 2018/12/01
3
+ ## v0.9.0
4
4
 
5
- First implementation
5
+ * Fixed [Unexpected town value](https://github.com/kengos/kamome/issues/1)
6
+ * Skip `block.call` in the case of `#ambisous_town` is true and is not a first appearance model
7
+ * Drop support `type: :hash`
8
+ * Support `throw :break` in passed block
9
+ ```rb
10
+ Kamome::import_general_all do |model, lineno|
11
+ throw :break if lineno > 10
12
+ # Do not use `break` without `throw`
13
+ # break if lineno > 10
14
+ end
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kamome (0.8.0)
4
+ kamome (0.9.0)
5
5
  rubyzip (~> 1.2)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -17,7 +17,7 @@ end
17
17
  * 全国一括 (全件, 差分)
18
18
  * 事業所(全件, 差分)
19
19
 
20
- 各CSVは共通のモデルにマッピングされます(type オプションで詳細なモデル or Hashに変更可能)
20
+ 各CSVは共通のモデルにマッピングされます(type オプションで詳細なモデルに変更可能)
21
21
 
22
22
  詳細は [Kamome::Models::Address](https://github.com/kengos/kamome/blob/master/lib/kamome/models/address.rb) を参照してください
23
23
 
@@ -85,12 +85,6 @@ end
85
85
 
86
86
  ### `Kamome.import_xxx` の model の型を変換したい
87
87
 
88
- #### Hash にする場合
89
-
90
- ```rb
91
- Kamome.import_general_all(type: :hash or Kamome::Operation::TYPE_HASH)
92
- ```
93
-
94
88
  #### DetailModel にする場合
95
89
 
96
90
  ```rb
@@ -11,9 +11,13 @@ module Kamome
11
11
  end
12
12
 
13
13
  def call(csv_path)
14
+ prev = nil
14
15
  ::CSV.foreach(csv_path) do |row|
15
16
  obj = transform(row)
16
- yield(obj, $INPUT_LINE_NUMBER) if block_given?
17
+ next if skip?(prev, obj)
18
+
19
+ yield(obj, $INPUT_LINE_NUMBER)
20
+ prev = obj
17
21
  end
18
22
  end
19
23
 
@@ -24,10 +28,7 @@ module Kamome
24
28
  end
25
29
 
26
30
  def transformed_method
27
- return :generate_hash if @operation.type_hash?
28
- return :generate_detail_model if @operation.type_detail?
29
-
30
- :generate_model
31
+ @operation.type_detail? ? :generate_detail_model : :generate_model
31
32
  end
32
33
 
33
34
  def transformer
@@ -41,5 +42,12 @@ module Kamome
41
42
  def general_transformer
42
43
  ::Kamome::Transformations::GeneralCsv.new
43
44
  end
45
+
46
+ def skip?(previous, current)
47
+ return false unless previous.respond_to?(:ambiguous_town)
48
+ return false unless previous.ambiguous_town
49
+
50
+ previous.zipcode == current.zipcode
51
+ end
44
52
  end
45
53
  end
data/lib/kamome/loader.rb CHANGED
@@ -10,6 +10,9 @@ module Kamome
10
10
  @config = config
11
11
  end
12
12
 
13
+ # @params [Operation] Kamome::Operation
14
+ # @yield [model, lineno] Any logic you want to execute
15
+ # Don't pass `-> { break }`, use `-> { throw :break }
13
16
  # @return [Array] csv digest
14
17
  def call(operation:, &block)
15
18
  operation.urls.map do |url|
@@ -29,7 +32,9 @@ module Kamome
29
32
  end
30
33
 
31
34
  def call_csv_handler(operation, csv_path, &block)
32
- ::Kamome::CsvHandler.new(operation).call(csv_path, &block)
35
+ catch(:break) do
36
+ ::Kamome::CsvHandler.new(operation).call(csv_path, &block)
37
+ end
33
38
  ::Digest::SHA256.file(csv_path).to_s
34
39
  ensure
35
40
  csv_path.delete if @config.cleanup
@@ -51,6 +51,12 @@ module Kamome
51
51
  # @return [Integer]
52
52
  attr_accessor :state
53
53
 
54
+ # @!attribute [rw] ambiguous_town
55
+ # 一町域が二以上の郵便番号で表される場合 true
56
+ # genre: :general のみ
57
+ # @return [Boolean]
58
+ attr_accessor :ambiguous_town
59
+
54
60
  STATE_NOT_CHANGE = 0
55
61
  STATE_UPDATE = 1
56
62
  STATE_DELETE = 2
@@ -73,7 +79,8 @@ module Kamome
73
79
  street: street,
74
80
  company_name: company_name,
75
81
  post_office_box: post_office_box,
76
- state: state
82
+ state: state,
83
+ ambiguous_town: ambiguous_town
77
84
  }
78
85
  end
79
86
 
@@ -2,7 +2,6 @@
2
2
 
3
3
  module Kamome
4
4
  class Operation
5
- TYPE_HASH = :hash
6
5
  TYPE_DETAIL = :detail
7
6
  TYPE_DEFAULT = :default
8
7
 
@@ -56,10 +55,6 @@ module Kamome
56
55
  @urls = urls
57
56
  end
58
57
 
59
- def type_hash?
60
- type == TYPE_HASH
61
- end
62
-
63
58
  def type_detail?
64
59
  type == TYPE_DETAIL
65
60
  end
@@ -66,7 +66,8 @@ module Kamome
66
66
  street: '',
67
67
  company_name: '',
68
68
  post_office_box: '',
69
- state: attributes[:state]
69
+ state: attributes[:state],
70
+ ambiguous_town: attributes[:ambiguous_town]
70
71
  }
71
72
  end
72
73
  end
@@ -69,7 +69,8 @@ module Kamome
69
69
  street: attributes[:street],
70
70
  company_name: attributes[:company_name],
71
71
  post_office_box: attributes[:post_office_box],
72
- state: convert_state(attributes[:state])
72
+ state: convert_state(attributes[:state]),
73
+ ambiguous_town: false
73
74
  }
74
75
  end
75
76
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kamome
4
- VERSION = '0.8.0'
4
+ VERSION = '0.9.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kamome
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kengos
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-01 00:00:00.000000000 Z
11
+ date: 2018-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -184,5 +184,5 @@ rubyforge_project:
184
184
  rubygems_version: 2.7.6
185
185
  signing_key:
186
186
  specification_version: 4
187
- summary: kamome-0.8.0
187
+ summary: kamome-0.9.0
188
188
  test_files: []