From 85235a9cf69f847c2451eacaf44a242e6433937a Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 29 Nov 2016 21:42:49 +0000 Subject: Introduce string matchers for matching style name --- mammoth/document_matchers.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'mammoth/document_matchers.py') diff --git a/mammoth/document_matchers.py b/mammoth/document_matchers.py index 2efd73f..af1fd47 100644 --- a/mammoth/document_matchers.py +++ b/mammoth/document_matchers.py @@ -1,5 +1,7 @@ import collections +import cobble + def paragraph(style_id=None, style_name=None, numbering=None): return ParagraphMatcher(style_id, style_name, numbering) @@ -35,3 +37,22 @@ class strikethrough(object): class comment_reference(object): element_type = "comment_reference" + + +def equal_to(value): + return StringMatcher(_operator_equal_to, value) + + +def _operator_equal_to(first, second): + return first.upper() == second.upper() + + +@cobble.data +class StringMatcher(object): + operator = cobble.field() + value = cobble.field() + + def matches(self, other): + return self.operator(self.value, other) + + -- cgit v1.2.3