Skip to content

Support for Multiple Rules Phase 1 Design Writeup

DashK edited this page Jan 18, 2016 · 1 revision

Support for Multiple Rules

Use Cases

  1. As an engineer, given a set of rules, I can ask rule engine to evaluate all rules for me based on given data.

In Scope

Simple boolean algebra with ANDs & ORs.

Not in Scope (Yet)

Parenthesis :)

Planned API

// 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