lib/rbbt/association/item.rb in rbbt-util-5.14.12 vs lib/rbbt/association/item.rb in rbbt-util-5.14.14
- old
+ new
@@ -60,15 +60,16 @@
Hash[*fields.zip(v).flatten]
}
end
property :tsv => :array do
- fields = self.info_fields
+ info_fields = self.info_fields
+ fields = [self.source_type, self.target_type].concat info_fields
type = [self.source_type, self.target_type] * "~"
tsv = TSV.setup({}, :key_field => type, :fields => fields, :type => :list, :namespace => self.namespace)
self.each do |match|
- tsv[match] = match.info.values_at *fields
+ tsv[match] = [match.source, match.target].concat match.info.values_at(*info_fields)
end
tsv
end
def self.incidence(pairs, key_field = nil)
@@ -91,7 +92,41 @@
matches.each do |s,hash|
matrix[s] = hash.values_at(*targets)
end
defined?(TSV)? TSV.setup(matrix, :key_field => (key_field || "Source") , :fields => targets, :type => :list) : matrix
+ end
+
+ def self._select_match(orig, elem)
+ if Array === orig and Array === elem
+ (orig & elem).any?
+ elsif Array === orig
+ orig.include? elem
+ elsif Array === elem
+ elem.include? orig
+ else
+ elem === orif
+ end
+ false
+ end
+
+ def self.select(list, method = nil, &block)
+ if method and method.any?
+ list.select do |item|
+ method.collect do |key,value|
+ case key
+ when :target
+ _select_match item.target, value
+ when :source
+ _select_match item.source, value
+ else
+ orig = item.info[key]
+ orig = orig.split(";;") if String orig
+ _select_match orig, value
+ end
+ end
+ end
+ else
+ list.select(&block)
+ end
end
end