Commit e78afef0 by liyijie

feat: update format

parent 7d2f8062
...@@ -238,23 +238,23 @@ module TalltyImportExport ...@@ -238,23 +238,23 @@ module TalltyImportExport
'' ''
end end
def try_chain(payload, arr) def try_chain(payload, arr)
arr.reduce(payload) do |r, m| arr.reduce(payload) do |r, m|
if m =~ /^\d+$/ && r.is_a?(Array) # If m is an integer string and r is an array if m =~ /^\d+$/ && r.is_a?(Array) # If m is an integer string and r is an array
r[m.to_i] r[m.to_i]
else else
r.try(m) || r.try(:[], m) r.try(m) || r.try(:[], m)
end
rescue StandardError
nil
end end
rescue StandardError
nil
end end
end
def try_method(payload, method, prefix: nil) def try_method(payload, method, prefix: nil)
prefix_arr = prefix.to_s.split(/\./) prefix_arr = prefix.to_s.split(/\./)
arr = method.split('.').flat_map { |m| m.include?('[') ? m.split(/\[\s*|\s*\]/).reject(&:empty?) : m } arr = method.split('.').flat_map { |m| m.include?('[') ? m.split(/\[\s*|\s*\]/).reject(&:empty?) : m }
try_chain record, prefix_arr + arr try_chain record, prefix_arr + arr
end end
# 根据数据类型 attr_type 进行数据的格式化 # 根据数据类型 attr_type 进行数据的格式化
def handle_format(data, header, **opts) def handle_format(data, header, **opts)
......
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