'use stric';
var fs = require('fs');

module.exports = rulezEngine;

function rulezEngine() {
    this.ruleset = {"name":null, "instance":null};
    this.setRuleSet = function(ruleset){
        this.ruleset.name = ruleset;
        path  = "ruleset/"+this.ruleset.name+".js";
        if (fs.existsSync(path)){
            this.ruleset.instance = require(path);        
            return true;
        }
        return false;
    };
    this.getRuleSet = function(){
        return this.ruleset.instance;
    };

    this.run = function(data)
    {
        rules = (this.ruleset.instance[this.ruleset.name].rules);
        results = [];
        for(i=0; i< rules.length; i++){
            if(typeof(rules[i])=='function'){
                results.push ( (rules[i])(data));
            }else{
                results.push( eval(rules[i]) );
            }
        }
        return results;
    };
    this.respond= function(results){
        returnType = (this.ruleset.instance[this.ruleset.name].returnType);
        if(returnType=='text'){
            return results.join();
       }else if(typeof(returnType)=='function'){
             return  ( (returnType)(results));
        }else if (returnType == "boolean"){
            return this.returnBoolean(results);
        } else if(returnType == "ResponseData"){
            return results;
        }
        return null;
    }
    this.returnBoolean = function (result){
        returnValue = true;
        for(r in result){
            returnValue = returnValue & result[r];
        }
        return returnValue;
    }
};
@@ -549,16 +549,20 @@
         
+var 
 rules = 
@@ -623,104 +623,404 @@
     
-results = %5B%5D;%0A        for(i=0; i%3C rules.length; i++)%7B%0A            if(typeof(rules%5Bi%5D)=='f
+var results = %5B%5D;%0A        return this.doRules(rules, data);%0A    %7D;%0A    this.doRules= function(rules, data)%0A    %7B%0A        var results = %5B%5D;%0A        for(i=0; i%3C rules.length; i++)%7B%0A            var type = Object.prototype.toString.call( rules%5Bi%5D );%0A            if(type =='%5Bobject Array%5D')%7B%0A                results.push ( this.doRules(rules%5Bi%5D, data) );%0A            %7Delse if(type =='%5Bobject F
 unction
+%5D
 ')%7B%0A
@@ -1185,25 +1185,24 @@
 sults;%0A    %7D
-;
 %0A    this.re
@@ -1231,24 +1231,28 @@
 s)%7B%0A        
+var 
 returnType =
@@ -1766,32 +1766,214 @@
 r(r in result)%7B%0A
+            var type = Object.prototype.toString.call(result%5Br%5D);%0A            if(type =='%5Bobject Array%5D')%7B%0A                returnValue = this.returnBoolean(result%5Br%5D);%0A            %7D%0A
             retu

support to nested rules.