Class: Klee::ConceptIndex

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/klee/concept_index.rb

Instance Method Summary collapse

Constructor Details

#initialize(ignore: [], threshold: 2) ⇒ ConceptIndex

Returns a new instance of ConceptIndex.



7
8
9
10
11
# File 'lib/klee/concept_index.rb', line 7

def initialize(ignore: [], threshold: 2)
  @ignore = Set.new(ignore.map(&:to_s))
  @threshold = threshold
  @data = Hash.new { |h, k| h[k] = {classes: Set.new, methods: Set.new} }
end

Instance Method Details

#[](concept) ⇒ Object



23
24
25
# File 'lib/klee/concept_index.rb', line 23

def [](concept)
  @data[concept.to_s]
end

#add(file_analyzer) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/klee/concept_index.rb', line 13

def add(file_analyzer)
  file_analyzer.class_names.each do |name|
    words_from(name).each { |word| @data[word][:classes] << name }
  end

  file_analyzer.method_names.each do |name|
    words_from(name).each { |word| @data[word][:methods] << name }
  end
end

#each(&block) ⇒ Object



27
28
29
# File 'lib/klee/concept_index.rb', line 27

def each(&block)
  filtered.each(&block)
end

#rankObject



31
32
33
# File 'lib/klee/concept_index.rb', line 31

def rank
  filtered.sort_by { |word, locs| -(locs[:classes].size + locs[:methods].size) }.to_h
end