Skip to content

Commit

Permalink
fix(models): fix full_title method
Browse files Browse the repository at this point in the history
Fix pattern matching for full_title method;
switch to looking for end punctuation in title
to determine separator between title and subtitle.
Add docstring.
  • Loading branch information
koeaw committed Aug 13, 2024
1 parent 2b14e7b commit d77f295
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions apis_ontology/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down

0 comments on commit d77f295

Please sign in to comment.