var RuleEngine = require('node-rules');
var titan = {
"product": "Titan",
"amount":"500",
"base":1,
"conversation":0.91,
};
var oxicash = {
}
var rules = [{
"name": "Product rule",
"description": "when the product matches Titan",
"priority": 1,
"on":1,
"condition":
function(fact,cb) {
cb(fact && (fact.product = "Titan"));
},
"consequence":
function(cb) {
console.log("Rule 1 matched for "+this.product);
var a = this.amount;
var b = this.base;
var c = this.conversation;
var result1= (a*c)/b;
console.log("the promotion cost is:"+result1);
this.result = true;
this.process = true;
cb();
}
}];
var R = new RuleEngine(rules);
R.execute(titan,function(result){
if(result.result)
console.log("\n-----u have discount----\n");
else
console.log("\n-----u dont have discount----\n");
console.log(result);
console.log(result1);
});
Am new to rule-engine. am trying to write a rule and i am made in "node-rules". but i came to know that "nools" was the best to write rules and it is light weight. but i don't know anything about nools. i am studied whole documentation but it is confusing me. So please can anyone help me by converting this rule which I have written in "node-rules" to "nools".Thanking you in advance for your kind information.