ApproximateFilter can match multiple values.
This commit is contained in:
parent
4343f72fab
commit
b0044f9bf0
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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',
|
||||
|
|
Loading…
Reference in New Issue