Class: Klee::Gestalt

Inherits:
Object
  • Object
show all
Defined in:
lib/klee/gestalt.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object, patterns:, ignored:) ⇒ Gestalt

Returns a new instance of Gestalt.



4
5
6
7
8
# File 'lib/klee/gestalt.rb', line 4

def initialize(object, patterns:, ignored:)
  @object = object
  @patterns = patterns
  @init_ignored = ignored
end

Instance Attribute Details

#patternsObject (readonly)

Returns the value of attribute patterns.



9
10
11
# File 'lib/klee/gestalt.rb', line 9

def patterns
  @patterns
end

Instance Method Details

#[](key) ⇒ Object



46
47
48
49
# File 'lib/klee/gestalt.rb', line 46

def [](key)
  trace if plot.empty?
  plot.fetch(key)
end

#comparableObject



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

def comparable
  @comparable ||= Set.new(@object.public_methods - ignored).map(&:to_s).freeze
end

#concepts(modifiers: [], threshold: 3) ⇒ Object



42
43
44
# File 'lib/klee/gestalt.rb', line 42

def concepts(modifiers: [], threshold: 3)
  @concepts ||= Concepts.new(*unusual, modifiers: modifiers).call(threshold)
end

#ignoredObject



19
20
21
# File 'lib/klee/gestalt.rb', line 19

def ignored
  @ignored ||= Array(@init_ignored) + Klee.public_instance_methods
end

#infixesObject



55
56
57
# File 'lib/klee/gestalt.rb', line 55

def infixes
  plot.select { |key, _| patterns.infixes.include?(key) }
end

#plotObject



15
16
17
# File 'lib/klee/gestalt.rb', line 15

def plot
  @plot ||= Hash.new { |h, k| h[k] = Set.new }
end

#prefixesObject



51
52
53
# File 'lib/klee/gestalt.rb', line 51

def prefixes
  plot.select { |key, _| patterns.prefixes.include?(key) }
end

#suffixesObject



59
60
61
# File 'lib/klee/gestalt.rb', line 59

def suffixes
  plot.select { |key, _| patterns.suffixes.include?(key) }
end

#trace(threshold: 6, modifiers: [], concept_threshold: 3) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/klee/gestalt.rb', line 27

def trace(threshold: 6, modifiers: [], concept_threshold: 3)
  plot.clear
  patterns.each do |pattern|
    matched = comparable.select { |method_name| pattern.match?(method_name.to_s) }
    unusual.delete_if { |strange| matched.include?(strange) }

    plot[patterns.key_for(pattern)].merge(matched)
  end

  plot["unusual"].merge(unusual_set(threshold))
  plot["concepts"].merge(concepts(modifiers: modifiers, threshold: concept_threshold))

  self
end

#unusualObject



11
12
13
# File 'lib/klee/gestalt.rb', line 11

def unusual
  @unusual ||= comparable.dup
end

#unusual?(*items) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/klee/gestalt.rb', line 63

def unusual?(*items)
  items.to_set <= plot["unusual"].flatten
end