From 0c13be7813f9a5aa181bc0b80bb1b12097d3f424 Mon Sep 17 00:00:00 2001 From: Bob Lannon Date: Tue, 16 Apr 2013 16:56:43 -0400 Subject: [PATCH] added new filter for changing field names (keys) --- saucebrush/filters.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/saucebrush/filters.py b/saucebrush/filters.py index bc1c7be..c942863 100644 --- a/saucebrush/filters.py +++ b/saucebrush/filters.py @@ -351,6 +351,23 @@ class FieldRenamer(Filter): record[dest] = record.pop(source) return record +class FieldNameModifier(Filter): + """ Filter that calls a given function on a given set of fields. + + FieldNameModifier(('spam','eggs'), abs) to call the abs method on the spam + and eggs field names in each record filtered. + """ + + def __init__(self, func): + super(FieldNameModifier, self).__init__() + self._filter_func = func + + def process_record(self, record): + for source in record.keys(): + dest = self._filter_func(source) + record[dest] = record.pop(source) + return record + class Splitter(Filter): """ Filter that splits nested data into different paths.