Created
October 9, 2012 07:44
-
-
Save DanielSzoska/3857224 to your computer and use it in GitHub Desktop.
Basisklasse für TextPatcher mit zu überschreibender Methode statt einer Helper-Funktion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TextPatcherBase(object): | |
def mangle_doc(self, doc, rflag, mapping): | |
raise NotImplementedError | |
def mangle_docs(self, patchfunc, mappings): | |
self.ndocs_patched = 0 | |
for doc in self.docs: | |
if doc.key in mappings: | |
self.mangle_doc(doc, True, mappings[doc.key]) | |
self.ndocs_patched += 1 | |
else: | |
# note this trick: mappings[None] is just | |
# a property object and not used as value, but valid syntax! | |
self.mangle_doc(doc, False, mappings[None]) | |
class TextPatcherRg(TextPatcherBase): | |
def mangle_doc(self, doc, rflag, mapping): | |
doc.search_euro('Abrechnungsgebühr {%} %', rflag, mapping.GebuehrNeu) | |
doc.match_nl(rflag, 11*' ' + 'minimal 0,15 EUR pro Rezept,') | |
doc.match_nl(rflag, 11*' ' + 'maximal 3,00 EUR pro Rezept') | |
doc.search_euro('+ 19,0 % MWST', rflag, mapping.MwSt) | |
doc.search_euro('Rechnungsbetrag', rflag, mapping.GebuehrBrutto) |
Eine TextPatcherBase macht schon Sinn, ja.
Mach mal! :-)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hallo Christian,
eine Alternative zu den Helper-Funktionen habe ich oben skizziert. Natürlich muß dann auch noch ein klein wenig was anderes geändert werden bezüglich Einlesen der CSV-Dateien (vielleicht auch eine Klasse).
Wie siehst Du das - Helper-Funktionen im Gegensatz zu einer Basisklasse, die abgeleitet werden muß, um ein entsprechendes Verhalten zu erzielen?