From d77f2954074326e55b01fd2fa59342867098a24f Mon Sep 17 00:00:00 2001 From: KK Date: Tue, 13 Aug 2024 14:41:31 +0200 Subject: [PATCH] fix(models): fix full_title method Fix pattern matching for full_title method; switch to looking for end punctuation in title to determine separator between title and subtitle. Add docstring. --- apis_ontology/models.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/apis_ontology/models.py b/apis_ontology/models.py index 56e3fd3..62ed4a2 100644 --- a/apis_ontology/models.py +++ b/apis_ontology/models.py @@ -85,12 +85,20 @@ def __str__(self): return self.title def full_title(self): - full_title = self.title + """ + Concatenate title and subtitle into a single string. + Use full stop as separator where title does not already + have end punctuation. + + :return: (full) title + :rtype: str + """ + full_title = title = self.title subtitle = self.subtitle - letter_or_digit = re.compile(r"[\W\d]", re.U) + end_punctuation = re.compile(r"[.?!…]", re.U) if subtitle: - if letter_or_digit.match(subtitle[0]): + if re.match(end_punctuation, title[-1]): full_title += f" {subtitle}" else: full_title += f". {subtitle}"