Class: Klee::Concepts

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*method_names, modifiers: []) ⇒ Concepts

Returns a new instance of Concepts.


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

def initialize(*method_names, modifiers: [])
  @method_names = method_names
  @modifiers = modifiers
end

Instance Attribute Details

#method_namesObject (readonly)

Returns the value of attribute method_names.


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

def method_names
  @method_names
end

#modifiersObject (readonly)

Returns the value of attribute modifiers.


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

def modifiers
  @modifiers
end

Instance Method Details

#call(threshold) ⇒ Object Also known as: []


11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/klee/concepts.rb', line 11

def call(threshold)
  warn "threshold is beyond the max count of #{max}" if threshold > max
  warn "threshold is below the min count of #{min}" if threshold < min
  clear
  @ideas = Set.new samples
    .select { |key, value|
      if value.to_i >= threshold
        key
      end
    }
    .compact
    .transform_keys(&:to_sym)
    .keys
end

#clearObject


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

def clear
  clearable = instance_variables - %i[@method_names @modifiers]
  clearable.each { send(:remove_instance_variable, _1) }
end

#each(&block) ⇒ Object


32
33
34
# File 'lib/klee/concepts.rb', line 32

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

#maxObject


40
41
42
# File 'lib/klee/concepts.rb', line 40

def max
  max_by { |_, v| v }.last
end

#minObject


44
45
46
# File 'lib/klee/concepts.rb', line 44

def min
  min_by { |_, v| v }.last
end

#minmaxObject


48
49
50
# File 'lib/klee/concepts.rb', line 48

def minmax
  [min, max]
end

#samplesObject


36
37
38
# File 'lib/klee/concepts.rb', line 36

def samples
  @samples ||= method_names.flat_map{ words(_1) }.tally
end