Skip to content

Instantly share code, notes, and snippets.

@DanielSzoska
Created October 9, 2012 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanielSzoska/3857224 to your computer and use it in GitHub Desktop.
Save DanielSzoska/3857224 to your computer and use it in GitHub Desktop.
Basisklasse für TextPatcher mit zu überschreibender Methode statt einer Helper-Funktion
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)
@DanielSzoska
Copy link
Author

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?

@ctismer
Copy link

ctismer commented Oct 9, 2012

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