Class: Klee::Gestalt
- Inherits:
-
Object
- Object
- Klee::Gestalt
- Defined in:
- lib/klee/gestalt.rb
Instance Attribute Summary collapse
-
#patterns ⇒ Object
readonly
Returns the value of attribute patterns.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #comparable ⇒ Object
- #concepts(modifiers: [], threshold: 3) ⇒ Object
- #ignored ⇒ Object
- #infixes ⇒ Object
-
#initialize(object, patterns:, ignored:) ⇒ Gestalt
constructor
A new instance of Gestalt.
- #plot ⇒ Object
- #prefixes ⇒ Object
- #suffixes ⇒ Object
- #trace(threshold: 6, modifiers: [], concept_threshold: 3) ⇒ Object
- #unusual ⇒ Object
- #unusual?(*items) ⇒ Boolean
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
#patterns ⇒ Object (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 |
#comparable ⇒ Object
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 |
#ignored ⇒ Object
18 19 20 |
# File 'lib/klee/gestalt.rb', line 18 def ignored @ignored ||= Array(@init_ignored) + Klee.public_instance_methods end |
#infixes ⇒ Object
54 55 56 |
# File 'lib/klee/gestalt.rb', line 54 def infixes plot.slice(*patterns.infixes) end |
#plot ⇒ Object
14 15 16 |
# File 'lib/klee/gestalt.rb', line 14 def plot @plot ||= Hash.new { |h, k| h[k] = Set.new } end |
#prefixes ⇒ Object
50 51 52 |
# File 'lib/klee/gestalt.rb', line 50 def prefixes plot.slice(*patterns.prefixes) end |
#suffixes ⇒ Object
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 |
#unusual ⇒ Object
10 11 12 |
# File 'lib/klee/gestalt.rb', line 10 def unusual @unusual ||= comparable.dup end |
#unusual?(*items) ⇒ Boolean
62 63 64 |
# File 'lib/klee/gestalt.rb', line 62 def unusual?(*items) items.to_set <= plot["unusual"].flatten end |