tellform/docs/Node-Rules/rules.logic-jump.js

237 lines
5.8 KiB
JavaScript
Raw Normal View History

2015-09-03 18:21:56 +00:00
//LogicJump (node-rules) Rules in JSON
var simpleFact = {
left:"user 4",
right:"something something user something",
};
var multiFact = {
operandTuples: [
{
left:"user 4",
right:"something something user something",
2016-04-29 06:00:41 +00:00
logicOp: "AND"
2015-09-03 18:21:56 +00:00
},
{
left:"something something user something",
right:"something",
2016-04-29 06:00:41 +00:00
logicOp: "OR"
2015-09-03 18:21:56 +00:00
}
],
left:"",
right:"",
logicOp:"",
2016-04-29 06:00:41 +00:00
prevResult: null
2015-09-03 18:21:56 +00:00
};
var _globalRules = function(){};
_globalRules.Equal = {
"condition" : function(R) {
if(this.operandTuples){
var currTuple = this.operandTuples.pop();
this.left = currTuple.left;
this.right = currTuple.right;
this.logicOp = currTuple.logicOp;
}
R.when(!(this.left === this.right));
},
"consequence" : function(R) {
if(prevResult !== null){
if(logicOp === "AND"){
2016-04-29 06:00:41 +00:00
2015-09-03 18:21:56 +00:00
}
}
this.result = false;
R.next();
},
};
_globalRules.NotEqual = {
"condition" : function(R) {
if(this.operandTuples){
var currTuple = this.operandTuples.pop();
this.left = currTuple.left;
this.right = currTuple.right;
}
R.when(!(this.left !== this.right));
},
"consequence" : function(R) {
this.result = false;
R.next();
2016-04-29 06:00:41 +00:00
}
2015-09-03 18:21:56 +00:00
};
_globalRules.AND = {
"condition" : function(R) {
if(this.operandTuples){
var currTuple = this.operandTuples.pop();
this.left = currTuple.left;
this.right = currTuple.right;
}
R.when(!(this.left && this.right));
},
"consequence" : function(R) {
this.result = false;
R.next();
2016-04-29 06:00:41 +00:00
}
2015-09-03 18:21:56 +00:00
};
_globalRules.OR = {
"condition" : function(R) {
if(this.operandTuples){
var currTuple = this.operandTuples.pop();
this.left = currTuple.left;
this.right = currTuple.right;
}
2016-04-29 06:00:41 +00:00
2015-09-03 18:21:56 +00:00
R.when(!(this.left || this.right));
},
"consequence" : function(R) {
this.result = false;
R.next();
},
};
var _stringRules = function(){};
_stringRules.prototype = _globalRules;
_stringRules.Contains = {
"condition" : function(R) {
if(this.operandTuples){
var currTuple = this.operandTuples.pop();
this.left = currTuple.left;
this.right = currTuple.right;
}
2016-04-29 06:00:41 +00:00
2015-09-03 18:21:56 +00:00
var contains = (this.left.indexOf(this.right) > -1);
R.when(!contains);
},
"consequence" : function(R) {
this.result = false;
R.next();
},
};
_stringRules.NotContains = {
"condition" : function(R) {
if(this.operandTuples){
var currTuple = this.operandTuples.pop();
this.left = currTuple.left;
this.right = currTuple.right;
}
2016-04-29 06:00:41 +00:00
2015-09-03 18:21:56 +00:00
var notContains = !(this.left.indexOf(this.right) > -1);
R.when(!notContains);
},
"consequence" : function(R) {
this.result = false;
R.next();
},
};
_stringRules.BeginsWith = {
"condition" : function(R) {
if(this.operandTuples){
var currTuple = this.operandTuples.pop();
this.left = currTuple.left;
this.right = currTuple.right;
}
2016-04-29 06:00:41 +00:00
2015-09-03 18:21:56 +00:00
R.when(!(this.left.indexOf(this.right) === 0));
},
"consequence" : function(R) {
this.result = false;
R.next();
},
};
_stringRules.EndsWith = {
"condition" : function(R) {
if(this.operandTuples){
var currTuple = this.operandTuples.pop();
this.left = currTuple.left;
this.right = currTuple.right;
}
2016-04-29 06:00:41 +00:00
2015-09-03 18:21:56 +00:00
var lenLeft = this.left.length;
var lenRight = this.right.length;
R.when(!(this.left.indexOf(this.right) === (lenLeft-lenRight)));
},
"consequence" : function(R) {
this.result = false;
R.next();
2016-04-29 06:00:41 +00:00
}
2015-09-03 18:21:56 +00:00
};
var _numberRules = function(){};
_numberRules.prototype = _globalRules;
_numberRules.GreaterThan = {
"condition" : function(R) {
if(this.operandTuples){
var currTuple = this.operandTuples.pop();
this.left = currTuple.left;
this.right = currTuple.right;
}
2016-04-29 06:00:41 +00:00
2015-09-03 18:21:56 +00:00
var greaterThan = (this.left > this.right);
R.when(!greaterThan);
},
"consequence" : function(R) {
this.result = false;
R.next();
2016-04-29 06:00:41 +00:00
}
2015-09-03 18:21:56 +00:00
};
_numberRules.SmallerThan = {
"condition" : function(R) {
if(this.operandTuples){
var currTuple = this.operandTuples.pop();
this.left = currTuple.left;
this.right = currTuple.right;
}
2016-04-29 06:00:41 +00:00
2015-09-03 18:21:56 +00:00
var smallerThan = (this.left < this.right);
R.when(!smallerThan);
},
"consequence" : function(R) {
this.result = false;
R.next();
},
};
_numberRules.GreaterThanOrEqual = {
"condition" : function(R) {
if(this.operandTuples){
var currTuple = this.operandTuples.pop();
this.left = currTuple.left;
this.right = currTuple.right;
}
2016-04-29 06:00:41 +00:00
2015-09-03 18:21:56 +00:00
var greaterThanOrEqual = (this.left >= this.right);
R.when(!greaterThanOrEqual);
},
"consequence" : function(R) {
this.result = false;
R.next();
2016-04-29 06:00:41 +00:00
}
2015-09-03 18:21:56 +00:00
};
_numberRules.SmallerThanOrEqual = {
"condition" : function(R) {
if(this.operandTuples){
var currTuple = this.operandTuples.pop();
this.left = currTuple.left;
this.right = currTuple.right;
}
2016-04-29 06:00:41 +00:00
2015-09-03 18:21:56 +00:00
var smallerThanOrEqual = (this.left <= this.right);
R.when(!smallerThanOrEqual);
},
"consequence" : function(R) {
this.result = false;
R.next();
2016-04-29 06:00:41 +00:00
}
2015-09-03 18:21:56 +00:00
};
module.exports = {
StringRules: _stringRules,
NumberRules: _numberRules,
BooleanRules: _globalRules,
};