blob: 7b9afee943c2d5e6fff878360f42349e86e02f95 [file] [log] [blame]
/**
* Create a pipe object, that holds a list of services
* meant to transform the KQ passed before it's finally
* passed to the search engine.
*
* @author Nils Diewald
*/
define(function () {
"use strict";
const notNullRe = new RegExp("[a-zA-Z0-9]");
// Trim and check
function _notNull (service) {
service = service.trim();
if (service.match(notNullRe)) {
return service;
};
return null;
}
return {
/**
* Constructor
*/
create : function () {
let obj = Object.create(this);
obj._pipe = [];
return obj;
},
/**
* Append service to pipe.
*/
append : function (service) {
service = _notNull(service);
if (service)
this._pipe.push(service);
},
/**
* Prepend service to pipe.
*/
prepend : function (service) {
service = _notNull(service);
if (service)
this._pipe.unshift(service);
},
/**
* Remove service from the pipe.
*/
remove : function (service) {
let i = this._pipe.indexOf(service);
if (i != -1) {
this._pipe.splice(i, 1);
};
},
/**
* The number of services in the pipe.
*/
size : function () {
return this._pipe.length;
},
/**
* Return the pipe as a string.
*/
toString : function () {
return this._pipe.join(',');
}
};
});