|
@@ -16,7 +16,7 @@ recreate_dir code_path
|
|
require 'csv'
|
|
require 'csv'
|
|
|
|
|
|
# 各类型定义
|
|
# 各类型定义
|
|
-TypeInfo = Struct.new(:data_type, :data_type_extra, :ref_info, :default_value)
|
|
|
|
|
|
+TypeInfo = Struct.new(:data_type, :data_type_extra, :ref_info, :default_value, :struct_info)
|
|
FieldInfo = Struct.new(:column_id, :identifier, :comment, :type_info)
|
|
FieldInfo = Struct.new(:column_id, :identifier, :comment, :type_info)
|
|
Table = Struct.new(:csv, :fields, :name2id, :id_field, :raw_name)
|
|
Table = Struct.new(:csv, :fields, :name2id, :id_field, :raw_name)
|
|
Ini = Struct.new(:io, :tables)
|
|
Ini = Struct.new(:io, :tables)
|
|
@@ -40,12 +40,13 @@ Dir["#{config_path}/*"].each do |path|
|
|
# 处理表头列
|
|
# 处理表头列
|
|
identifiers.each_with_index do |identifier, index|
|
|
identifiers.each_with_index do |identifier, index|
|
|
next if identifier.nil? || identifier.empty?
|
|
next if identifier.nil? || identifier.empty?
|
|
- type_info = TypeInfo.new(nil, nil, nil, nil)
|
|
|
|
|
|
+ type_info = TypeInfo.new(nil, nil, nil, nil, nil)
|
|
type_infos[index].gsub(/\s+/, '').scan(/[(:|,|@|=)][a-zA-Z_]+/).each do |info|
|
|
type_infos[index].gsub(/\s+/, '').scan(/[(:|,|@|=)][a-zA-Z_]+/).each do |info|
|
|
type_info.data_type = info[1..info.size] if info.start_with?(':')
|
|
type_info.data_type = info[1..info.size] if info.start_with?(':')
|
|
type_info.data_type_extra = info[1..info.size] if info.start_with?(',')
|
|
type_info.data_type_extra = info[1..info.size] if info.start_with?(',')
|
|
type_info.ref_info = convert_case(info[1..info.size]) if info.start_with?('@')
|
|
type_info.ref_info = convert_case(info[1..info.size]) if info.start_with?('@')
|
|
type_info.default_value = info[1..info.size] if info.start_with?('=')
|
|
type_info.default_value = info[1..info.size] if info.start_with?('=')
|
|
|
|
+ type_info.struct_info = info[1..info.size] if info.start_with?('!')
|
|
end
|
|
end
|
|
field = FieldInfo.new(index, identifier, comments[index], type_info)
|
|
field = FieldInfo.new(index, identifier, comments[index], type_info)
|
|
# 处理特殊类型的字段
|
|
# 处理特殊类型的字段
|
|
@@ -91,7 +92,9 @@ inis.each_pair do |ini_name, ini_data|
|
|
# 逐行扫描
|
|
# 逐行扫描
|
|
while !table.csv.eof?
|
|
while !table.csv.eof?
|
|
line = table.csv.readline
|
|
line = table.csv.readline
|
|
- id = line[table.id_field.column_id].upcase
|
|
|
|
|
|
+ id = line[table.id_field.column_id]
|
|
|
|
+ next if id.nil? || id.empty?
|
|
|
|
+ id = id.upcase
|
|
buffer.puts "[#{id}]"
|
|
buffer.puts "[#{id}]"
|
|
table.fields.each do |field|
|
|
table.fields.each do |field|
|
|
value = line[field.column_id]
|
|
value = line[field.column_id]
|
|
@@ -100,6 +103,7 @@ inis.each_pair do |ini_name, ini_data|
|
|
if field.type_info.ref_info
|
|
if field.type_info.ref_info
|
|
ref_table = tables[field.type_info.ref_info]
|
|
ref_table = tables[field.type_info.ref_info]
|
|
value = value.split(',').collect do |ref_name|
|
|
value = value.split(',').collect do |ref_name|
|
|
|
|
+ ref_name.strip!
|
|
ref_table.name2id[ref_name] || ref_name.upcase
|
|
ref_table.name2id[ref_name] || ref_name.upcase
|
|
end.join(',')
|
|
end.join(',')
|
|
# 数据类型处理
|
|
# 数据类型处理
|
|
@@ -109,9 +113,10 @@ inis.each_pair do |ini_name, ini_data|
|
|
when 'text'
|
|
when 'text'
|
|
index = 0
|
|
index = 0
|
|
value = value.split(',').collect do |text|
|
|
value = value.split(',').collect do |text|
|
|
- key = "C:#{table_name.upcase}:#{field.column_id}:#{count}"
|
|
|
|
|
|
+ key = "#{id}"
|
|
key = "#{key}:#{index}" if index > 0
|
|
key = "#{key}:#{index}" if index > 0
|
|
- texts[key] = text
|
|
|
|
|
|
+ global_key = "C:#{table_name}:#{field.identifier}:#{key}"
|
|
|
|
+ texts[global_key] = text
|
|
index += 1
|
|
index += 1
|
|
key
|
|
key
|
|
end.join(',')
|
|
end.join(',')
|