2015-11-12 07:31:25 +00:00
|
|
|
/* jslint node: true */
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// ENiGMA½
|
|
|
|
var acsParser = require('./acs_parser.js');
|
|
|
|
|
|
|
|
var _ = require('lodash');
|
|
|
|
var assert = require('assert');
|
|
|
|
|
2016-02-03 04:35:59 +00:00
|
|
|
exports.checkAcs = checkAcs;
|
2015-11-12 07:31:25 +00:00
|
|
|
exports.getConditionalValue = getConditionalValue;
|
|
|
|
|
2016-02-03 04:35:59 +00:00
|
|
|
function checkAcs(client, acsString) {
|
|
|
|
return acsParser.parse(acsString, { client : client } );
|
|
|
|
}
|
|
|
|
|
2015-11-12 07:31:25 +00:00
|
|
|
function getConditionalValue(client, condArray, memberName) {
|
|
|
|
assert(_.isObject(client));
|
|
|
|
assert(_.isArray(condArray));
|
|
|
|
assert(_.isString(memberName));
|
|
|
|
|
2015-11-14 19:22:21 +00:00
|
|
|
var matchCond = _.find(condArray, function cmp(cond) {
|
2015-11-15 00:51:05 +00:00
|
|
|
return _.has(cond, 'acs') && acsParser.parse(cond.acs, { client : client } );
|
2015-11-12 07:31:25 +00:00
|
|
|
});
|
2015-11-15 00:51:05 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// If no matchCond, look for a default entry. That is,
|
|
|
|
// a entry without a 'acs' string.
|
|
|
|
//
|
|
|
|
if(!matchCond) {
|
|
|
|
matchCond = _.find(condArray, function cmp(cond) {
|
|
|
|
return !_.has(cond, 'acs');
|
|
|
|
});
|
|
|
|
}
|
2015-11-14 19:22:21 +00:00
|
|
|
|
|
|
|
if(matchCond) {
|
|
|
|
return matchCond[memberName];
|
|
|
|
}
|
2015-11-12 07:31:25 +00:00
|
|
|
}
|