tallty_import_export 1.0.21 → 1.0.25

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: 9253a9c6be1b5829d258f8a3c7cf59729e84d1e8c8daeba7890fb050fe61708c
4
- data.tar.gz: 7c3e2b5ba2c20149f47f0d19b26710d5e722ed946b483e4e78dcd1a9c1b00247
3
+ metadata.gz: bc0e8d3d68e999a6b3f67fa31dbec4ac510d948ddb391a38ef12e06cd8d2674c
4
+ data.tar.gz: 0c6751bba32cf9eeed209efa7aef3514cdd64d0c3db4518e717b46336b96e174
5
5
  SHA512:
6
- metadata.gz: dbb47e4a94cd7b7c3fe059aa5f0fc3d0384b023360452e62ab37dc4c524a8f5258e3827e6bded58a8931f36ce569d079f02424578e48a1f9c9281a6dbc7ad001
7
- data.tar.gz: 7101fb1b0ef57e7ea7983e949e7a4b88dc986fd382061da954609755b94efa3a4b26d4a23049ef146444c823ed81f52d8ded585460dc91b7ecfde858d0fcce36
6
+ metadata.gz: 79b629e699808fd77b57631abd8fa2cabdc43140d524f9287c0a9ea1c5d5dfdf8fe5013f9d4422d23b7487c88c2154e39f818f2f1d32171be83ab20fb5c3ba92
7
+ data.tar.gz: 3fcc361eebf3f0ec4cc1d9b10e0d6a5060c3fbb7c22a75841397cb172e24abd77d0d9e0cb2c6a02eec7be1702c6455aa3068a2d08eb184ae1d9f50e593c00574
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tallty_import_export (0.1.0)
4
+ tallty_import_export (1.0.24)
5
5
  activesupport
6
6
  caxlsx
7
7
  redis
@@ -14,33 +14,35 @@ PATH
14
14
  GEM
15
15
  remote: https://gems.ruby-china.com/
16
16
  specs:
17
- activemodel (6.0.3.4)
18
- activesupport (= 6.0.3.4)
19
- activesupport (6.0.3.4)
17
+ activemodel (6.1.4.1)
18
+ activesupport (= 6.1.4.1)
19
+ activesupport (6.1.4.1)
20
20
  concurrent-ruby (~> 1.0, >= 1.0.2)
21
- i18n (>= 0.7, < 2)
22
- minitest (~> 5.1)
23
- tzinfo (~> 1.1)
24
- zeitwerk (~> 2.2, >= 2.2.2)
25
- caxlsx (3.0.2)
21
+ i18n (>= 1.6, < 2)
22
+ minitest (>= 5.1)
23
+ tzinfo (~> 2.0)
24
+ zeitwerk (~> 2.3)
25
+ caxlsx (3.1.1)
26
26
  htmlentities (~> 4.3, >= 4.3.4)
27
- mimemagic (~> 0.3)
27
+ marcel (~> 1.0)
28
28
  nokogiri (~> 1.10, >= 1.10.4)
29
29
  rubyzip (>= 1.3.0, < 3)
30
- concurrent-ruby (1.1.7)
30
+ concurrent-ruby (1.1.9)
31
31
  diff-lcs (1.4.4)
32
32
  htmlentities (4.3.4)
33
- i18n (1.8.5)
33
+ i18n (1.8.10)
34
34
  concurrent-ruby (~> 1.0)
35
- mimemagic (0.3.5)
36
- mini_portile2 (2.4.0)
37
- minitest (5.14.2)
38
- nokogiri (1.10.10)
39
- mini_portile2 (~> 2.4.0)
35
+ marcel (1.0.2)
36
+ mini_portile2 (2.6.1)
37
+ minitest (5.14.4)
38
+ nokogiri (1.12.4)
39
+ mini_portile2 (~> 2.6.1)
40
+ racc (~> 1.4)
41
+ racc (1.5.2)
40
42
  rake (12.3.3)
41
- redis (4.2.5)
42
- redis-objects (1.5.0)
43
- redis (~> 4.0)
43
+ redis (4.4.0)
44
+ redis-objects (1.5.1)
45
+ redis (~> 4.2)
44
46
  roo (2.8.3)
45
47
  nokogiri (~> 1)
46
48
  rubyzip (>= 1.3.0, < 3.0.0)
@@ -62,18 +64,17 @@ GEM
62
64
  rspec-support (~> 3.10.0)
63
65
  rspec-support (3.10.0)
64
66
  ruby-ole (1.2.12.2)
65
- rubyzip (2.3.0)
66
- spreadsheet (1.2.6)
67
- ruby-ole (>= 1.0)
68
- tallty_duck_record (1.0.2)
69
- activemodel (~> 6.0.3)
70
- activesupport (~> 6.0.3)
67
+ rubyzip (2.3.2)
68
+ spreadsheet (1.3.0)
69
+ ruby-ole
70
+ tallty_duck_record (1.1.3)
71
+ activemodel (>= 5.0)
72
+ activesupport (>= 5.0)
71
73
  tallty_form (1.0.0)
72
74
  tallty_duck_record
73
- thread_safe (0.3.6)
74
- tzinfo (1.2.8)
75
- thread_safe (~> 0.1)
76
- zeitwerk (2.4.1)
75
+ tzinfo (2.0.4)
76
+ concurrent-ruby (~> 1.0)
77
+ zeitwerk (2.4.2)
77
78
  zip-zip (0.3)
78
79
  rubyzip (>= 1.0.0)
79
80
 
@@ -86,4 +87,4 @@ DEPENDENCIES
86
87
  tallty_import_export!
87
88
 
88
89
  BUNDLED WITH
89
- 2.1.4
90
+ 2.2.15
@@ -27,6 +27,7 @@ module TalltyImportExport
27
27
  # index: 数组方式,需要嵌套拿到里面的
28
28
  # merge: true/false,默认false,某一列,如果上下行的内容相同,则直接合并单元格
29
29
  # json: model_payload,代表存储在某一个列中
30
+ # select: [{ label: '已报备', value: 'submitted'}, ...],需要转换的枚举类型
30
31
 
31
32
  def export_xlsx records, **options
32
33
  records = with_scope records
@@ -79,16 +80,16 @@ module TalltyImportExport
79
80
  if respond_to?(:first_header)
80
81
  row_index = Axlsx.col_ref(headers.size - 1)
81
82
  sheet.merge_cells("A1:#{row_index}1")
82
- sheet.add_row [first_header], style: title1, height: 40
83
+ sheet.add_row [first_header], style: title1, height: 30
83
84
  end
84
85
 
85
- sheet.add_row headers.map{|header| header[:name]}, style: title2, height: 39
86
+ sheet.add_row headers.map{|header| header[:name]}, style: title2, height: 25
86
87
 
87
88
  last_row = nil
88
89
  merge_column_hash = {}
89
90
  first_content_row_index = respond_to?(:first_header) ? 2 : 1
90
91
 
91
- each_method = records.is_a?(Array) ? :each : :each
92
+ each_method = @each_method || :each
92
93
  records.send(each_method).with_index do |record, index|
93
94
  row = []
94
95
  headers.each_with_index do |header, col_index|
@@ -122,15 +123,21 @@ module TalltyImportExport
122
123
  end
123
124
  end
124
125
 
126
+ # 地处整体配置信息
127
+ def export_options
128
+ {}
129
+ end
130
+
125
131
  def process_options options = {}
126
- options = options.with_indifferent_access
132
+ options = export_options.merge(options).with_indifferent_access
127
133
 
128
- @row_height ||= options.delete(:row_height) || 35
134
+ @row_height ||= options.delete(:row_height) || 25
129
135
  @width ||= (options.delete(:width) || 20).to_f
130
136
  @filename ||= options.delete(:filename)
131
137
  @group_by ||= options.delete(:group_by)
132
138
  @group_where = "#{@group_by}_eq" if @group_by.present?
133
139
  @headers ||= options.delete(:headers)
140
+ @each_method ||= options.delete(:each_method)
134
141
  end
135
142
 
136
143
  def with_scope records
@@ -138,7 +145,7 @@ module TalltyImportExport
138
145
  end
139
146
 
140
147
  def export_headers_result
141
- @headers || export_headers
148
+ @headers ||= export_headers&.with_indifferent_access
142
149
  end
143
150
 
144
151
  def export_headers **args
@@ -159,13 +166,14 @@ module TalltyImportExport
159
166
  else
160
167
  try_method(record, header[:key])
161
168
  end
162
- handle_format(data, header)
169
+ data = handle_format(data, header)
170
+ data = handle_select(data, header)
163
171
  rescue
164
172
  ''
165
173
  end
166
174
 
167
175
  def try_chain record, arr
168
- arr.inject(record, :try)
176
+ arr.reduce(record) { |r, m| r.try(m) || r.try(:[], m) }
169
177
  end
170
178
 
171
179
  def try_method record, method
@@ -186,5 +194,14 @@ module TalltyImportExport
186
194
  data
187
195
  end
188
196
  end
197
+
198
+ def handle_select data, header
199
+ if header[:select].present?
200
+ select_option = header[:select].find { |option| option[:value].to_s == data.to_s }
201
+ select_option.present? ? select_option[:label] : data
202
+ else
203
+ data
204
+ end
205
+ end
189
206
  end
190
207
  end
@@ -51,7 +51,7 @@ module TalltyImportExport
51
51
  end
52
52
 
53
53
  def process_options options
54
- options = options.with_indifferent_access
54
+ options = import_options.merge(options).with_indifferent_access
55
55
  @headers = options.delete(:headers) || import_headers
56
56
  @primary_keys = options.delete(:primary_keys) || @headers.map { |header| header[:primary_key] ? header[:key].to_sym : nil }.compact
57
57
  @params = options
@@ -89,7 +89,7 @@ module TalltyImportExport
89
89
  h[header[:json]] ||= {}
90
90
  h[header[:json]][k] = val
91
91
  elsif header[:finder]
92
- $SAFE = 2
92
+ # $SAFE = 2
93
93
  h[k.to_sym] = eval header[:finder]
94
94
  else
95
95
  h[k.to_sym] = val
@@ -104,7 +104,11 @@ module TalltyImportExport
104
104
  end
105
105
 
106
106
  def import_headers_result
107
- @headers ||= import_headers
107
+ @headers ||= import_headers&.with_indifferent_access
108
+ end
109
+
110
+ def import_options
111
+ {}
108
112
  end
109
113
 
110
114
  def import_headers **args
@@ -1,3 +1,3 @@
1
1
  module TalltyImportExport
2
- VERSION = "1.0.21"
2
+ VERSION = "1.0.25"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tallty_import_export
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.21
4
+ version: 1.0.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - liyijie
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-02 00:00:00.000000000 Z
11
+ date: 2021-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zip-zip