diff --git a/lib/filters/equality_filter.js b/lib/filters/equality_filter.js index f8999fd..5a1fa7e 100644 --- a/lib/filters/equality_filter.js +++ b/lib/filters/equality_filter.js @@ -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; }; diff --git a/lib/filters/ge_filter.js b/lib/filters/ge_filter.js index 9177c4c..a2aa7d4 100644 --- a/lib/filters/ge_filter.js +++ b/lib/filters/ge_filter.js @@ -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; }; diff --git a/lib/filters/le_filter.js b/lib/filters/le_filter.js index eb87149..e90fa03 100644 --- a/lib/filters/le_filter.js +++ b/lib/filters/le_filter.js @@ -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; }; diff --git a/tst/filters/eq.test.js b/tst/filters/eq.test.js index 7d963ed..0da92f9 100644 --- a/tst/filters/eq.test.js +++ b/tst/filters/eq.test.js @@ -57,6 +57,17 @@ test('match true', function(t) { }); +test('match multiple', function(t) { + var f = new EqualityFilter({ + attribute: 'foo', + value: 'bar' + }); + t.ok(f); + t.ok(f.matches({ foo: ['plop', 'bar'] })); + t.end(); +}); + + test('match false', function(t) { var f = new EqualityFilter({ attribute: 'foo', diff --git a/tst/filters/ge.test.js b/tst/filters/ge.test.js index 52b6cb2..604ad14 100644 --- a/tst/filters/ge.test.js +++ b/tst/filters/ge.test.js @@ -57,6 +57,16 @@ test('match true', function(t) { }); +test('match multiple', function(t) { + var f = new GreaterThanEqualsFilter({ + attribute: 'foo', + value: 'bar' + }); + t.ok(f); + t.ok(f.matches({ foo: ['beuha', 'baz'] })); + t.end(); +}); + test('match false', function(t) { var f = new GreaterThanEqualsFilter({ attribute: 'foo', diff --git a/tst/filters/le.test.js b/tst/filters/le.test.js index 21380b4..545cdc3 100644 --- a/tst/filters/le.test.js +++ b/tst/filters/le.test.js @@ -57,6 +57,17 @@ test('match true', function(t) { }); +test('match multiple', function(t) { + var f = new LessThanEqualsFilter({ + attribute: 'foo', + value: 'bar' + }); + t.ok(f); + t.ok(f.matches({ foo: ['abc', 'beuha'] })); + t.end(); +}); + + test('match false', function(t) { var f = new LessThanEqualsFilter({ attribute: 'foo',