lib/rbbt/tsv/attach.rb in rbbt-util-5.17.77 vs lib/rbbt/tsv/attach.rb in rbbt-util-5.17.78

- old
+ new

@@ -174,11 +174,11 @@ CMD.cmd("paste #{ files.collect{|f| "'#{f}'"} * " "} -d'#{delim}' |sed 's/#{delim}[^\\t]*//g'", :pipe => true) end def attach(other, options = {}) options = Misc.add_defaults options, :in_namespace => false, :persist_input => true - fields, one2one = Misc.process_options options, :fields, :one2one + fields, one2one, complete = Misc.process_options options, :fields, :one2one, :complete in_namespace = options[:in_namespace] unless TSV === other other_identifier_file = other.identifier_files.first if other.respond_to? :identifier_files other = TSV.open(other, :persist => options[:persist_input].to_s == "true") @@ -192,9 +192,32 @@ fields = other.fields - [key_field].concat(self.fields) if fields.nil? end other_filename = other.respond_to?(:filename) ? other.filename : other.inspect Log.low("Attaching fields:#{Misc.fingerprint fields } from #{other_filename}.") + + if complete + fill = TrueClass === complete ? nil : complete + missing = other.keys - self.keys + case type + when :single + missing.each do |k| + self[k] = nil + end + when :list + missing.each do |k| + self[k] = [nil] * field_length + end + when :double + missing.each do |k| + self[k] = [[]] * field_length + end + when :flat + missing.each do |k| + self[k] = [] + end + end + end same_key = true begin case when (key_field == other.key_field and same_key)