diffusion
Version:
Diffusion JavaScript client
49 lines (38 loc) • 1.35 kB
JavaScript
var inherits = require('inherits');
var utils = require('topics/topic-path-utils');
var TopicSelector = require('../../selectors/topic-selector');
var DQ = utils.DescendantQualifier;
function TopicPathSelector(components) {
var remainder = components.remainder;
if (components.type === TopicSelector.Type.PATH) {
if (components.prefix === "") {
throw new Error("Topic path must have at least one part: " + remainder);
}
if (components.prefix.indexOf("//") > -1) {
throw new Error("Topic path contains empty part: " + remainder);
}
}
this.qualifier = components.qualifier;
this.path = components.prefix;
TopicSelector.call(
this,
components.type,
components.prefix,
components.expression);
}
inherits(TopicPathSelector, TopicSelector);
TopicPathSelector.prototype.doSelects = function (topicPath) {
var match = this.path === topicPath;
var descendants = topicPath.indexOf(this.path + '/') === 0;
switch (this.qualifier) {
case DQ.MATCH :
return match;
case DQ.DESCENDANTS_OF_MATCH :
return descendants;
case DQ.MATCH_AND_DESCENDANTS :
return match || descendants;
default :
return false;
}
};
module.exports = TopicPathSelector;