lib/rbbt/tsv/change_id.rb in rbbt-util-5.14.34 vs lib/rbbt/tsv/change_id.rb in rbbt-util-5.14.35
- old
+ new
@@ -92,15 +92,20 @@
fields = source ? [source] : nil
files.each do |file|
if TSV === file
all_fields = file.all_fields
target = file.fields.first if target.nil?
- return file.index(options.merge(:target => target, :fields => fields, :order => true)) if (source.nil? or all_fields.include? source) and all_fields.include? target
+ if (source.nil? or all_fields.include? source) and all_fields.include? target
+ return file.index(options.merge(:target => target, :fields => fields, :order => true))
+ end
else
all_fields = TSV.parse_header(file).all_fields
target = all_fields[1] if target.nil?
- return TSV.index(file, options.merge(:target => target, :fields => fields, :order => true)) if (source.nil? or all_fields.include? source) and all_fields.include? target
+ if (source.nil? or all_fields.include? source) and all_fields.include? target
+ index = TSV.index(file, options.merge(:target => target, :fields => fields, :order => true))
+ return index
+ end
end
end
files.each do |file|
all_fields = TSV === file ? file.all_fields : TSV.parse_header(file).all_fields
@@ -110,26 +115,27 @@
other_all_fields = TSV === other_file ? other_file.all_fields : TSV.parse_header(other_file).all_fields
common_field = (all_fields & other_all_fields).first
- if common_field and (source.nil? or fields.include? source) and all_fields.include? common_field and
- other_all_fields.include? common_field and other_all_fields.include? target
+ if common_field and (source.nil? or all_fields.include? source) and other_all_fields.include? target
- return Persist.persist_tsv(nil, Misc.fingerprint(files), {:files => files, :source => source, :target => target}, :prefix => "Translation index", :persist => options[:persist]) do |data|
+ index = Persist.persist_tsv(nil, Misc.fingerprint(files), {:files => files, :source => source, :target => target}, :prefix => "Translation index", :persist => options[:persist]) do |data|
+
index = TSV === file ?
file.index(options.merge(:target => common_field, :fields => fields)) :
TSV.index(file, options.merge(:target => common_field, :fields => fields))
other_index = TSV === other_file ?
other_file.index(options.merge(:target => target, :fields => [common_field])) :
TSV.index(other_file, options.merge(:target => target, :fields => [common_field]))
data.serializer = :clean
+
+ # ToDo: remove the need to to the `to_list` transformation
data.merge! index.to_list.attach(other_index.to_list).slice([target]).to_single
-
- data
end
+ return index
end
end
end
return nil
end