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.



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

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

Instance Attribute Details

#patternsObject (readonly)

Returns the value of attribute patterns.



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

def patterns
  @patterns
end

Instance Method Details

#[](key) ⇒ Object



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

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

#comparableObject



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

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

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



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

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

#ignoredObject



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

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

#infixesObject



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

def infixes
  plot.slice(*patterns.infixes)
end

#plotObject



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

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

#prefixesObject



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

def prefixes
  plot.slice(*patterns.prefixes)
end

#suffixesObject



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

def suffixes
  plot.slice(*patterns.suffixes)
end

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



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

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



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

def unusual
  @unusual ||= comparable.dup
end

#unusual?(*items) ⇒ Boolean

Returns:

  • (Boolean)


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

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