Class: Klee::Concepts
- Inherits:
-
Object
- Object
- Klee::Concepts
- Includes:
- Enumerable
- Defined in:
- lib/klee/concepts.rb
Instance Attribute Summary collapse
-
#method_names ⇒ Object
readonly
Returns the value of attribute method_names.
-
#modifiers ⇒ Object
readonly
Returns the value of attribute modifiers.
Instance Method Summary collapse
- #call(threshold) ⇒ Object (also: #[])
- #clear ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(*method_names, modifiers: []) ⇒ Concepts
constructor
A new instance of Concepts.
- #max ⇒ Object
- #min ⇒ Object
- #minmax ⇒ Object
- #samples ⇒ Object
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_names ⇒ Object (readonly)
Returns the value of attribute method_names.
9 10 11 |
# File 'lib/klee/concepts.rb', line 9 def method_names @method_names end |
#modifiers ⇒ Object (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 |
#clear ⇒ Object
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 |
#max ⇒ Object
40 41 42 |
# File 'lib/klee/concepts.rb', line 40 def max max_by { |_, v| v }.last end |
#min ⇒ Object
44 45 46 |
# File 'lib/klee/concepts.rb', line 44 def min min_by { |_, v| v }.last end |
#minmax ⇒ Object
48 49 50 |
# File 'lib/klee/concepts.rb', line 48 def minmax [min, max] end |
#samples ⇒ Object
36 37 38 |
# File 'lib/klee/concepts.rb', line 36 def samples @samples ||= method_names.flat_map{ words(_1) }.tally end |