Commit 7517e09b by liyijie

feat: import支持dot_hash的方式,进行json类型属性的赋值

parent d9f4c4d5
...@@ -108,8 +108,9 @@ module TalltyImportExport ...@@ -108,8 +108,9 @@ module TalltyImportExport
def convert_data(line_info) def convert_data(line_info)
info = line_info.with_indifferent_access info = line_info.with_indifferent_access
import_headers_result.each_with_object({}) do |header, h| import_headers_result.each_with_object({}.with_indifferent_access) do |header, h|
k = header[:key] k = header[:key]
k_arr = k.to_s.split(/\./)
v = info[k] v = info[k]
# header[:convert] = handle_xxx # header[:convert] = handle_xxx
# handle_xxx(val, processing_line_info, raw_line_info) # handle_xxx(val, processing_line_info, raw_line_info)
...@@ -123,6 +124,12 @@ module TalltyImportExport ...@@ -123,6 +124,12 @@ module TalltyImportExport
elsif header[:finder] elsif header[:finder]
# $SAFE = 2 # $SAFE = 2
h[k.to_sym] = eval header[:finder] h[k.to_sym] = eval header[:finder]
elsif k_arr.size > 1
# hash设置
attr = k_arr.first
val = { k_arr[1..-1].join('.') => v }.to_nested_hash
h[attr.to_sym] ||= {}
h[attr.to_sym].merge! val
else else
h[k.to_sym] = val h[k.to_sym] = val
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