lib/rast/parameter_generator.rb in rast-0.9.0 vs lib/rast/parameter_generator.rb in rast-0.10.0

- old
+ new

@@ -1,8 +1,7 @@ # frozen_string_literal: true -require 'pry' require 'yaml' require 'rast/rast_spec' require 'rast/rules/rule' require 'rast/rules/rule_evaluator' require 'rast/rules/rule_validator' @@ -78,10 +77,29 @@ ) param end + # Detects if rule config has one outcome to one token mapping. + def one_to_one(outcome_to_clause) + outcome_to_clause.each do |outcome, clause| + return false if RuleEvaluator.tokenize(clause: clause).size > 1 + end + + true + end + + # Used to optimize by detecting the variables if rules config is a 1 outcome to 1 rule token. + def detect_variables(spec_config) + return nil unless one_to_one(spec_config['rules']) + + { vars: spec_config['rules'].values } + end + def instantiate_spec(spec_config) + + spec_config['variables'] = detect_variables(spec_config) if spec_config['variables'].nil? + spec = RastSpec.new( description: spec_config[:description], variables: spec_config['variables'], rule: Rule.new(rules: spec_config['rules']) )