Class: Klee::CollaboratorIndex
- Inherits:
-
Object
- Object
- Klee::CollaboratorIndex
- Defined in:
- lib/klee/collaborator_index.rb
Instance Method Summary collapse
- #add(file_analyzer) ⇒ Object
- #clusters ⇒ Object
- #for(collaborator) ⇒ Object
-
#initialize(ignore: [], threshold: 2) ⇒ CollaboratorIndex
constructor
A new instance of CollaboratorIndex.
- #pairs(scope: :file) ⇒ Object
Constructor Details
#initialize(ignore: [], threshold: 2) ⇒ CollaboratorIndex
Returns a new instance of CollaboratorIndex.
5 6 7 8 9 10 |
# File 'lib/klee/collaborator_index.rb', line 5 def initialize(ignore: [], threshold: 2) @ignore = Set.new(ignore.map(&:to_s)) @threshold = threshold @file_pairs = Hash.new(0) @method_pairs = Hash.new(0) end |
Instance Method Details
#add(file_analyzer) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/klee/collaborator_index.rb', line 12 def add(file_analyzer) # File-level pairs collabs = filter(file_analyzer.collaborators.uniq) each_pair(collabs) { |pair| @file_pairs[pair] += 1 } # Method-level pairs file_analyzer.method_collaborators.each_value do |method_collabs| filtered = filter(method_collabs.uniq) each_pair(filtered) { |pair| @method_pairs[pair] += 1 } end end |
#clusters ⇒ Object
36 37 38 |
# File 'lib/klee/collaborator_index.rb', line 36 def clusters build_clusters(pairs) end |
#for(collaborator) ⇒ Object
30 31 32 33 34 |
# File 'lib/klee/collaborator_index.rb', line 30 def for(collaborator) name = collaborator.to_s pairs.select { |pair, _| pair.include?(name) } .transform_keys { |pair| (pair - [name]).first } end |
#pairs(scope: :file) ⇒ Object
24 25 26 27 28 |
# File 'lib/klee/collaborator_index.rb', line 24 def pairs(scope: :file) source = (scope == :method) ? @method_pairs : @file_pairs source.select { |_, count| count >= @threshold } .sort_by { |_, count| -count }.to_h end |