Module: AssociationItem
- Extended by:
- Entity
- Defined in:
- lib/rbbt/association/item.rb
Constant Summary
Constants included
from Entity
Entity::UNPERSISTED_PREFIX
Instance Attribute Summary
Attributes included from Entity
#all_formats
Class Method Summary
collapse
Methods included from Entity
extended
Class Method Details
.incidence(pairs, key_field = nil) ⇒ Object
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/rbbt/association/item.rb', line 46
def self.incidence(pairs, key_field = nil)
matrix = {}
targets = []
sources = []
matches = {}
pairs.each do |p|
s, sep, t = p.partition "~"
sources << s
targets << t
matches[s] ||= Hash.new{false}
matches[s][t] = true
end
sources.uniq!
targets = targets.uniq.sort
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
|