Skip to content

Commit 23d037a

Browse files
authored
Merge pull request kennknowles#34 from dchourasia/patch-1
Updated Filter.py to implement update function
2 parents 003a0b7 + a77121e commit 23d037a

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

jsonpath_ng/ext/filter.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ def find(self, datum):
4848
len(list(filter(lambda x: x.find(datum.value[i]),
4949
self.expressions))))]
5050

51+
def update(self, data, val):
52+
if type(data) is list:
53+
for index, item in enumerate(data):
54+
shouldUpdate = len(self.expressions) == len(list(filter(lambda x: x.find(item), self.expressions)))
55+
if shouldUpdate:
56+
if hasattr(val, '__call__'):
57+
val.__call__(data[index], data, index)
58+
else:
59+
data[index] = val
60+
return data
61+
5162
def __repr__(self):
5263
return '%s(%r)' % (self.__class__.__name__, self.expressions)
5364

0 commit comments

Comments
 (0)