lib/rbbt/util/tsv/parse.rb in rbbt-util-2.0.1 vs lib/rbbt/util/tsv/parse.rb in rbbt-util-2.1.0

- old
+ new

@@ -84,11 +84,11 @@ key, fields = Misc.process_options options, :key, :fields if key_field.nil? key_pos = key - key_field, fields = nil + other_pos = fields else all_fields = [key_field].concat other_fields key_pos = Misc.field_position(all_fields, key) @@ -156,11 +156,11 @@ id = ids.shift ids.each do |id2| data[id2] = "__Ref:#{id}" end next if data.include?(id) and type != :flat - if key_field.nil? + if other_pos.nil? or (fields == nil and type == :flat) other_pos = (0..(parts.length - 1)).to_a other_pos.delete key_pos end if type == :flat @@ -197,11 +197,11 @@ ids.collect!{|id| id.downcase} if case_insensitive id = ids.shift ids.each do |id2| data[id2] = "__Ref:#{id}" end - if key_field.nil? + if other_pos.nil? or (fields == nil and type == :flat) other_pos = (0..(parts.length - 1)).to_a other_pos.delete key_pos end extra = parts.values_at(*other_pos).collect{|f| parse_fields(f, sep2)} @@ -250,9 +250,11 @@ end data[key] = new_values end end + fields = nil if Fixnum === fields or (Array === fields and fields.select{|f| Fixnum === f}.any?) + fields ||= other_fields [data, {:key_field => key_field, :fields => fields, :type => type, :case_insensitive => case_insensitive, :namespace => namespace, :datadir => options[:datadir], :identifiers => options[:identifiers], :cast => !!cast}] end end