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.



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

def initialize(*method_names, modifiers: [])
  @method_names = method_names
  @modifiers = Array(modifiers).map(&:to_s)
end

Instance Attribute Details

#method_names ⇒ Object (readonly)

Returns the value of attribute method_names.



13
14
15
# File 'lib/klee/concepts.rb', line 13

def method_names
  @method_names
end

#modifiers ⇒ Object (readonly)

Returns the value of attribute modifiers.



13
14
15
# File 'lib/klee/concepts.rb', line 13

def modifiers
  @modifiers
end

Instance Method Details

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



15
16
17
18
19
20
21
22
# File 'lib/klee/concepts.rb', line 15

def call(threshold)
  unless samples.empty?
    warn "threshold is beyond the max count of #{max}" if threshold > max
    warn "threshold is below the min count of #{min}" if threshold < min
  end

  method_groups.select { |_, methods| methods.size >= threshold }
end

#clear ⇒ Object



25
26
27
28
# File 'lib/klee/concepts.rb', line 25

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

#each(&block) ⇒ Object



30
31
32
# File 'lib/klee/concepts.rb', line 30

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

#max ⇒ Object



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

def max
  return 0 if samples.empty?

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

#min ⇒ Object



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

def min
  return 0 if samples.empty?

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

#minmax ⇒ Object



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

def minmax
  [min, max]
end

#samples ⇒ Object



34
35
36
# File 'lib/klee/concepts.rb', line 34

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