wlxml: metadata - additional iterator, filtering
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 21 Jan 2014 10:04:31 +0000 (11:04 +0100)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 21 Jan 2014 10:09:08 +0000 (11:09 +0100)
src/wlxml/extensions/metadata/metadata.js

index b30b94c..b19cd52 100644 (file)
@@ -90,8 +90,16 @@ _.extend(Metadata.prototype, {
         }
     }),
 
-    forEach: function(callback) {
-        return this._rows.forEach(callback);
+    _iter: function(method, callback, key) {
+        return this._rows
+            .filter(function(row) { return !key || row.getKey() === key; })
+            [method](function(row) { return callback(row); });
+    },
+    forEach: function(callback, key) {
+        return this._iter('forEach', callback, key);
+    },
+    some: function(callback, key) {
+        return this._iter('some', callback, key);
     },
     add: function(rowDesc, options) {
         var row;