ApproximateFilter can match multiple values.

This commit is contained in:
Mathieu Lecarme 2011-12-04 23:23:39 +01:00
parent 4343f72fab
commit b0044f9bf0
2 changed files with 19 additions and 2 deletions

View File

@ -48,8 +48,14 @@ ApproximateFilter.prototype.matches = function(target) {
throw new TypeError('target (object) required');
var matches = false;
if (target.hasOwnProperty(this.attribute))
matches = (this.value === target[this.attribute]);
if (target.hasOwnProperty(this.attribute)) {
var tv = target[this.attribute];
if (Array.isArray(tv)) {
matches = (tv.indexOf(this.value) != -1);
} else {
matches = (this.value === target[this.attribute]);
}
}
return matches;
};

View File

@ -57,6 +57,17 @@ test('match true', function(t) {
});
test('match multiple', function(t) {
var f = new ApproximateFilter({
attribute: 'foo',
value: 'bar'
});
t.ok(f);
t.ok(f.matches({ foo: ['steak', 'bar']}));
t.ok(!f.matches({ foo: ['nihhh', 'rabbit']}));
t.end();
});
test('match false', function(t) {
var f = new ApproximateFilter({
attribute: 'foo',