Commit bc77df7b by liyijie

Add handle_select

parent 3a13f44b
PATH PATH
remote: . remote: .
specs: specs:
tallty_import_export (0.1.0) tallty_import_export (1.0.22)
activesupport activesupport
caxlsx caxlsx
redis redis
...@@ -14,33 +14,35 @@ PATH ...@@ -14,33 +14,35 @@ PATH
GEM GEM
remote: https://gems.ruby-china.com/ remote: https://gems.ruby-china.com/
specs: specs:
activemodel (6.0.3.4) activemodel (6.1.4.1)
activesupport (= 6.0.3.4) activesupport (= 6.1.4.1)
activesupport (6.0.3.4) activesupport (6.1.4.1)
concurrent-ruby (~> 1.0, >= 1.0.2) concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 0.7, < 2) i18n (>= 1.6, < 2)
minitest (~> 5.1) minitest (>= 5.1)
tzinfo (~> 1.1) tzinfo (~> 2.0)
zeitwerk (~> 2.2, >= 2.2.2) zeitwerk (~> 2.3)
caxlsx (3.0.2) caxlsx (3.1.0)
htmlentities (~> 4.3, >= 4.3.4) htmlentities (~> 4.3, >= 4.3.4)
mimemagic (~> 0.3) marcel (~> 1.0)
nokogiri (~> 1.10, >= 1.10.4) nokogiri (~> 1.10, >= 1.10.4)
rubyzip (>= 1.3.0, < 3) rubyzip (>= 1.3.0, < 3)
concurrent-ruby (1.1.7) concurrent-ruby (1.1.9)
diff-lcs (1.4.4) diff-lcs (1.4.4)
htmlentities (4.3.4) htmlentities (4.3.4)
i18n (1.8.5) i18n (1.8.10)
concurrent-ruby (~> 1.0) concurrent-ruby (~> 1.0)
mimemagic (0.3.5) marcel (1.0.1)
mini_portile2 (2.4.0) mini_portile2 (2.6.1)
minitest (5.14.2) minitest (5.14.4)
nokogiri (1.10.10) nokogiri (1.12.4)
mini_portile2 (~> 2.4.0) mini_portile2 (~> 2.6.1)
racc (~> 1.4)
racc (1.5.2)
rake (12.3.3) rake (12.3.3)
redis (4.2.5) redis (4.4.0)
redis-objects (1.5.0) redis-objects (1.5.1)
redis (~> 4.0) redis (~> 4.2)
roo (2.8.3) roo (2.8.3)
nokogiri (~> 1) nokogiri (~> 1)
rubyzip (>= 1.3.0, < 3.0.0) rubyzip (>= 1.3.0, < 3.0.0)
...@@ -62,18 +64,17 @@ GEM ...@@ -62,18 +64,17 @@ GEM
rspec-support (~> 3.10.0) rspec-support (~> 3.10.0)
rspec-support (3.10.0) rspec-support (3.10.0)
ruby-ole (1.2.12.2) ruby-ole (1.2.12.2)
rubyzip (2.3.0) rubyzip (2.3.2)
spreadsheet (1.2.6) spreadsheet (1.2.9)
ruby-ole (>= 1.0) ruby-ole
tallty_duck_record (1.0.2) tallty_duck_record (1.1.3)
activemodel (~> 6.0.3) activemodel (>= 5.0)
activesupport (~> 6.0.3) activesupport (>= 5.0)
tallty_form (1.0.0) tallty_form (1.0.0)
tallty_duck_record tallty_duck_record
thread_safe (0.3.6) tzinfo (2.0.4)
tzinfo (1.2.8) concurrent-ruby (~> 1.0)
thread_safe (~> 0.1) zeitwerk (2.4.2)
zeitwerk (2.4.1)
zip-zip (0.3) zip-zip (0.3)
rubyzip (>= 1.0.0) rubyzip (>= 1.0.0)
...@@ -86,4 +87,4 @@ DEPENDENCIES ...@@ -86,4 +87,4 @@ DEPENDENCIES
tallty_import_export! tallty_import_export!
BUNDLED WITH BUNDLED WITH
2.1.4 2.2.15
...@@ -27,6 +27,7 @@ module TalltyImportExport ...@@ -27,6 +27,7 @@ module TalltyImportExport
# index: 数组方式,需要嵌套拿到里面的 # index: 数组方式,需要嵌套拿到里面的
# merge: true/false,默认false,某一列,如果上下行的内容相同,则直接合并单元格 # merge: true/false,默认false,某一列,如果上下行的内容相同,则直接合并单元格
# json: model_payload,代表存储在某一个列中 # json: model_payload,代表存储在某一个列中
# select: [{ label: '已报备', value: 'submitted'}, ...],需要转换的枚举类型
def export_xlsx records, **options def export_xlsx records, **options
records = with_scope records records = with_scope records
...@@ -138,7 +139,7 @@ module TalltyImportExport ...@@ -138,7 +139,7 @@ module TalltyImportExport
end end
def export_headers_result def export_headers_result
@headers || export_headers @headers ||= export_headers&.with_indifferent_access
end end
def export_headers **args def export_headers **args
...@@ -159,7 +160,8 @@ module TalltyImportExport ...@@ -159,7 +160,8 @@ module TalltyImportExport
else else
try_method(record, header[:key]) try_method(record, header[:key])
end end
handle_format(data, header) data = handle_format(data, header)
data = handle_select(data, header)
rescue rescue
'' ''
end end
...@@ -186,5 +188,14 @@ module TalltyImportExport ...@@ -186,5 +188,14 @@ module TalltyImportExport
data data
end end
end end
def handle_select data, header
if header[:select].present?
select_option = header[:select].find { |option| option[:value].to_s == data.to_s }
select_option.present? ? select_option[:label] : data
else
data
end
end
end end
end end
...@@ -104,7 +104,7 @@ module TalltyImportExport ...@@ -104,7 +104,7 @@ module TalltyImportExport
end end
def import_headers_result def import_headers_result
@headers ||= import_headers @headers ||= import_headers&.with_indifferent_access
end end
def import_headers **args def import_headers **args
......
module TalltyImportExport module TalltyImportExport
VERSION = "1.0.22" VERSION = "1.0.23"
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment