tallty_import_export 1.0.20 → 1.0.24

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: b1cb38513ee9efd2e26a8cabc623e52306cf5f2a3ecf53711993aeb8067b2915
4
- data.tar.gz: bcc91bcc85017141640c259777996e2036347fc68a978403d22a7085c704c1b1
3
+ metadata.gz: f5b4baee923834e5a843ab33b902d60cb200c4706c278793f45626fb1a93182e
4
+ data.tar.gz: 83feee2c88ef9d40ab6273002bb0764447ed450d9262e97bad4ba0a5781f5f7c
5
5
  SHA512:
6
- metadata.gz: 6465b690fba9935d30109b3423119cc9a93dd6b5872eacc647404400ed50da95156fbb9d1b35d94c7f733fef2236601de11ce244ab76618789ed2756027fe23b
7
- data.tar.gz: 326fe9117444b0cb0461731181ac2131584b36b64582c8b2a21fab3eb7de761bf27c23d3d710ef703eded66f76fb106373628552437bf042d4371178448c3eb8
6
+ metadata.gz: 12c078e974198c3471a9c211a80edaeb7dfe7b1bd8e551320663bb08d9f933d74aa734cdb40c8b1a58175eebff3d98b1676f52c9da4f2c8eb160010cb462139e
7
+ data.tar.gz: 2fa62a1f0d57499115c734ca854274b354e55e3ad752e0b55c339b8a71668fcff9051062839a4bedce680df721d9629fde9fb59be62904b89b8cd4e037dade56
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.22)
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.0)
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.1)
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.2.9)
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,10 +80,10 @@ 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 = {}
@@ -125,7 +126,7 @@ module TalltyImportExport
125
126
  def process_options options = {}
126
127
  options = options.with_indifferent_access
127
128
 
128
- @row_height ||= options.delete(:row_height) || 35
129
+ @row_height ||= options.delete(:row_height) || 25
129
130
  @width ||= (options.delete(:width) || 20).to_f
130
131
  @filename ||= options.delete(:filename)
131
132
  @group_by ||= options.delete(:group_by)
@@ -138,7 +139,7 @@ module TalltyImportExport
138
139
  end
139
140
 
140
141
  def export_headers_result
141
- @headers || export_headers
142
+ @headers ||= export_headers&.with_indifferent_access
142
143
  end
143
144
 
144
145
  def export_headers **args
@@ -159,13 +160,14 @@ module TalltyImportExport
159
160
  else
160
161
  try_method(record, header[:key])
161
162
  end
162
- handle_format(data, header)
163
+ data = handle_format(data, header)
164
+ data = handle_select(data, header)
163
165
  rescue
164
166
  ''
165
167
  end
166
168
 
167
169
  def try_chain record, arr
168
- arr.inject(record, :try)
170
+ arr.reduce(record) { |r, m| r.try(m) || r.try(:[], m) }
169
171
  end
170
172
 
171
173
  def try_method record, method
@@ -179,9 +181,18 @@ module TalltyImportExport
179
181
  when 'string'
180
182
  data.to_s
181
183
  when 'datetime'
182
- data ? data.strftime('%F %H:%M') : nil
184
+ data ? data.in_time_zone.strftime('%F %H:%M') : nil
183
185
  when 'date'
184
- data ? data.strftime('%F') : nil
186
+ data ? data.in_time_zone.strftime('%F') : nil
187
+ else
188
+ data
189
+ end
190
+ end
191
+
192
+ def handle_select data, header
193
+ if header[:select].present?
194
+ select_option = header[:select].find { |option| option[:value].to_s == data.to_s }
195
+ select_option.present? ? select_option[:label] : data
185
196
  else
186
197
  data
187
198
  end
@@ -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,7 @@ 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
108
  end
109
109
 
110
110
  def import_headers **args
@@ -1,3 +1,3 @@
1
1
  module TalltyImportExport
2
- VERSION = "1.0.20"
2
+ VERSION = "1.0.24"
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.20
4
+ version: 1.0.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - liyijie
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-06-30 00:00:00.000000000 Z
11
+ date: 2021-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zip-zip