lib/rbbt/util/tsv/index.rb in rbbt-util-2.1.0 vs lib/rbbt/util/tsv/index.rb in rbbt-util-3.0.2

- old
+ new

@@ -230,10 +230,11 @@ new end def self.field_matches(tsv, values) + values = [values] if not Array === values if values.flatten.sort[0..9].compact.collect{|n| n.to_i} == (1..10).to_a return {} end key_field = tsv.key_field @@ -245,11 +246,11 @@ } if tsv.type == :double tsv.through do |key,entry_values| fields.zip(entry_values).each do |field,entry_field_values| - field_values[field].concat entry_field_values + field_values[field].concat entry_field_values unless entry_field_values.nil? end end else tsv.through do |key,entry_values| fields.zip(entry_values).each do |field,entry_field_values| @@ -267,9 +268,13 @@ field_values end def field_matches(values) TSV.field_matches(self, values) + end + + def guess_field(values) + field_matches(values).sort_by{|field, matches| matches.uniq.length}.last end def sorted_index(pos_start = nil, pos_end = nil) raise "Please specify indexing fields" if (pos_start.nil? and fields.length > 2)