tasks/lib/conditions.js
function(phrasesArray) {
    var deferred = Q.defer();

    if (phrasesArray === undefined) {
        phrasesArray = [];
    }

    // Default conditionsObject
    var conditionsObject = {
        atLeastOneUrl: {
            ruleScores: [],
            ruleValues: [],
            ignoredRules: []
        }
    };

    // Parse each phrase
    var errorFound = phrasesArray.some(function(phrase) {
        
        // Test if phrase is about global score
        var globalScore = extractGlobalScore(phrase);
        
        // or about a rule score
        var ruleScore = extractRuleScore(phrase);
        
        // or about "any rule"
        var anyRule = extractAnyRule(phrase);
        
        // about ignoring a rule score
        var ignoreRule = extractIgnoreRule(phrase);
        
        // about a rule value
        var ruleValue = extractRuleValue(phrase);


        if (globalScore !== null) {
            conditionsObject.atLeastOneUrl.globalScore = globalScore;
        } else if (anyRule !== null) {
            conditionsObject.atLeastOneUrl.anyRule = anyRule;
        } else if (ruleScore !== null) {
            conditionsObject.atLeastOneUrl.ruleScores.push(ruleScore);
        } else if (ignoreRule !== null) {
            conditionsObject.atLeastOneUrl.ignoredRules.push(ignoreRule);
        } else if (ruleValue !== null) {
            conditionsObject.atLeastOneUrl.ruleValues.push(ruleValue);
        } else {
            deferred.reject('Failed to parse this failCondition: ' + phrase);
            return true;
        }
    });

    if (!errorFound) {
        deferred.resolve(conditionsObject);
    }

    return deferred.promise;
}
function(phrasesArray) {
    var deferred = Q.defer();

    if (phrasesArray === undefined) {
        phrasesArray = [];
    }

    // Default conditionsObject
    var conditionsObject = {
        atLeastOneUrl: {
            ruleScores: [],
            ruleValues: [],
            ignoredRules: []
        }
    };

    // Parse each phrase
    var errorFound = phrasesArray.some(function(phrase) {
        
        // Test if phrase is about global score
        var globalScore = extractGlobalScore(phrase);
        
        // or about a rule score
        var ruleScore = extractRuleScore(phrase);
        
        // or about "any rule"
        var anyRule = extractAnyRule(phrase);
        
        // about ignoring a rule score
        var ignoreRule = extractIgnoreRule(phrase);
        
        // about a rule value
        var ruleValue = extractRuleValue(phrase);


        if (globalScore !== null) {
            conditionsObject.atLeastOneUrl.globalScore = globalScore;
        } else if (anyRule !== null) {
            conditionsObject.atLeastOneUrl.anyRule = anyRule;
        } else if (ruleScore !== null) {
            conditionsObject.atLeastOneUrl.ruleScores.push(ruleScore);
        } else if (ignoreRule !== null) {
            conditionsObject.atLeastOneUrl.ignoredRules.push(ignoreRule);
        } else if (ruleValue !== null) {
            conditionsObject.atLeastOneUrl.ruleValues.push(ruleValue);
        } else {
            deferred.reject('Failed to parse this failCondition: ' + phrase);
            return true;
        }
    });

    if (!errorFound) {
        deferred.resolve(conditionsObject);
    }

    return deferred.promise;
}
function ( phrasesArray ) { var deferred = Q . defer ( ) ; if ( phrasesArray === undefined ) { phrasesArray = [ ] ; } // Default conditionsObject var conditionsObject = { atLeastOneUrl : { ruleScores : [ ] , ruleValues : [ ] , ignoredRules : [ ] } } ; // Parse each phrase var errorFound = phrasesArray . some ( function ( phrase ) { // Test if phrase is about global score var globalScore = extractGlobalScore ( phrase ) ; // or about a rule score var ruleScore = extractRuleScore ( phrase ) ; // or about "any rule" var anyRule = extractAnyRule ( phrase ) ; // about ignoring a rule score var ignoreRule = extractIgnoreRule ( phrase ) ; // about a rule value var ruleValue = extractRuleValue ( phrase ) ; if ( globalScore !== null ) { conditionsObject . atLeastOneUrl . globalScore = globalScore ; } else if ( anyRule !== null ) { conditionsObject . atLeastOneUrl . anyRule = anyRule ; } else if ( ruleScore !== null ) { conditionsObject . atLeastOneUrl . ruleScores . push ( ruleScore ) ; } else if ( ignoreRule !== null ) { conditionsObject . atLeastOneUrl . ignoredRules . push ( ignoreRule ) ; } else if ( ruleValue !== null ) { conditionsObject . atLeastOneUrl . ruleValues . push ( ruleValue ) ; } else { deferred . reject ( 'Failed to parse this failCondition: ' + phrase ) ; return true ; } } ) ; if ( ! errorFound ) { deferred . resolve ( conditionsObject ) ; } return deferred . promise ; }
Reads an array of phrases, understand them and transform them into a conditionsObject
Reads an array of phrases understand them and transform them into a conditionsObject