-
Notifications
You must be signed in to change notification settings - Fork 0
Support for Multiple Rules Phase 1 Design Writeup
DashK edited this page Jan 18, 2016
·
1 revision
- As an engineer, given a set of rules, I can ask rule engine to evaluate all rules for me based on given data.
Simple boolean algebra with ANDs & ORs.
Parenthesis :)
// Create an instance of Rule Engine
var RuleEngine = require('rule-engine');
var Rule = require('rule');
var ruleEngine = new RuleEngine();
// Add rules
var rule1 = new Rule('rule-1', 'return data.name === "hello world";');
var rule2 = new Rule('rule-2', 'return data.name === "foo";');
ruleEngine.addRule(rule1);
ruleEngine.addRule(rule2);
// Set condition
ruleEngine.setRuleConditions("rule-1 OR rule-2");
// Evaluate
ruleEngine.isMatch({ name: "hello world" }); // Returns true
ruleEngine.isMatch({ name: "foo" }); // Returns true
ruleEngine.isMatch({ name: "fluffy" }); // returns false