Class: GeneGenie::TemplateEvaluator
- Inherits:
-
Object
- Object
- GeneGenie::TemplateEvaluator
- Defined in:
- lib/gene_genie/template_evaluator.rb
Overview
A Template Evaluator provides certain analysis and useful information about templates. A template is always treated internally as an Array of Hashes.
Instance Method Summary collapse
-
#hash_valid?(hash_under_test) ⇒ Boolean
Verifies that the given hash conforms to the constraints specified in the hash template.
-
#initialize(template) ⇒ TemplateEvaluator
constructor
A new instance of TemplateEvaluator.
- #permutations ⇒ Object
-
#recommended_size ⇒ Object
Suggests a recommended GenePool size.
Constructor Details
#initialize(template) ⇒ TemplateEvaluator
Returns a new instance of TemplateEvaluator.
7 8 9 |
# File 'lib/gene_genie/template_evaluator.rb', line 7 def initialize(template) @template = template end |
Instance Method Details
#hash_valid?(hash_under_test) ⇒ Boolean
Verifies that the given hash conforms to the constraints specified in the hash template
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gene_genie/template_evaluator.rb', line 32 def hash_valid?(hash_under_test) begin @template.each_with_index do |h, index| h.each do |k, v| return false unless hash_under_test[index][k] return false unless hash_under_test[index][k] >= v.min return false unless hash_under_test[index][k] <= v.max end end rescue return false end return true end |
#permutations ⇒ Object
11 12 13 14 15 |
# File 'lib/gene_genie/template_evaluator.rb', line 11 def permutations @permutations ||= @template.map { |hash| hash.map { |_, v| v.size }.reduce(:*) }.reduce(:*) end |
#recommended_size ⇒ Object
Suggests a recommended GenePool size. returns a minimum of 6 unless the total number of permutations is below that. Otherwise, returns 1/1000th of the number of permutations up to a maximum of 20000
22 23 24 25 26 27 28 |
# File 'lib/gene_genie/template_evaluator.rb', line 22 def recommended_size [ [((Math.log(permutations))**2).ceil, 20000].min, [6, permutations].min, 3 ].max end |