Class: Pal::Operation::RuleFactory
- Inherits:
-
Object
- Object
- Pal::Operation::RuleFactory
- Defined in:
- lib/pal/operation/filter_evaluator.rb
Overview
Class to manage the rules provided
Class Method Summary collapse
- .from_group_rules(group_rule) ⇒ Array<Rule>
-
.from_hash(rule_hash) ⇒ Rule
rubocop:disable Metrics/AbcSize.
Class Method Details
.from_group_rules(group_rule) ⇒ Array<Rule>
54 55 56 57 58 59 60 |
# File 'lib/pal/operation/filter_evaluator.rb', line 54 def self.from_group_rules(group_rule) rules = group_rule.fetch("rules", []) rules.map do |rule_hash| from_hash(rule_hash) end end |
.from_hash(rule_hash) ⇒ Rule
rubocop:disable Metrics/AbcSize
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/pal/operation/filter_evaluator.rb', line 34 def self.from_hash(rule_hash) return nil if rule_hash.nil? || rule_hash.keys.empty? if rule_hash.key?("condition") condition = rule_hash.fetch("condition") rules = RuleFactory.from_group_rules(rule_hash) return AndGroupRule.new(rules) if condition.casecmp("and").zero? return OrGroupRule.new(rules) if condition.casecmp("or").zero? raise "Invalid condition [#{condition}] passed." end return OperatorRule.new(rule_hash) if rule_hash.key?("operator") raise "Hash is malformed." end |