Commit bc77df7b by liyijie

Add handle_select

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