Filter: filter against one or multiple values.

This commit is contained in:
Mathieu Lecarme 2011-12-07 21:22:34 +01:00
parent 7b5bef86d5
commit eadf70e994
3 changed files with 15 additions and 35 deletions

View File

@ -47,20 +47,14 @@ EqualityFilter.prototype.matches = function(target) {
if (typeof(target) !== 'object')
throw new TypeError('target (object) required');
var matches = false;
if (target.hasOwnProperty(this.attribute)) {
if (Array.isArray(target[this.attribute])) {
for (var i = 0; i < target[this.attribute].length; i++) {
matches = (this.value === target[this.attribute][i]);
if (matches)
break;
}
} else {
matches = (this.value === target[this.attribute]);
}
var value = this.value;
return Filter.multi_test(
function(v) { return value === v; },
target[this.attribute]);
}
return matches;
return false;
};

View File

@ -48,21 +48,14 @@ GreaterThanEqualsFilter.prototype.matches = function(target) {
if (typeof(target) !== 'object')
throw new TypeError('target (object) required');
var matches = false;
if (target.hasOwnProperty(this.attribute)) {
if (Array.isArray(target[this.attribute])) {
for (var i = 0; i < target[this.attribute].length; i++) {
matches = (this.value <= target[this.attribute][i]);
if (matches)
break;
}
} else {
matches = (this.value <= target[this.attribute]);
}
var value = this.value;
return Filter.multi_test(
function(v) { return value <= v; },
target[this.attribute]);
}
return matches;
return false;
};

View File

@ -48,21 +48,14 @@ LessThanEqualsFilter.prototype.matches = function(target) {
if (typeof(target) !== 'object')
throw new TypeError('target (object) required');
var matches = false;
if (target.hasOwnProperty(this.attribute)) {
if (Array.isArray(target[this.attribute])) {
for (var i = 0; i < target[this.attribute].length; i++) {
matches = (this.value >= target[this.attribute][i]);
if (matches)
break;
}
} else {
matches = (this.value >= target[this.attribute]);
}
var value = this.value;
return Filter.multi_test(
function(v) { return value >= v; },
target[this.attribute]);
}
return matches;
return false;
};