From 77b46392054b34a1558fa8d49f999c4e079e7042 Mon Sep 17 00:00:00 2001 From: Sabe Jones Date: Thu, 19 Jan 2017 17:22:41 +0000 Subject: [PATCH] fix(decode): better title casing Fixes #18. --- lib/cardlib.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/lib/cardlib.py b/lib/cardlib.py index fdf04ed..1a7332c 100644 --- a/lib/cardlib.py +++ b/lib/cardlib.py @@ -11,7 +11,19 @@ try: from titlecase import titlecase except ImportError: def titlecase(s): - return s.title() + s = s.title() + smallwords = [ + "'S", + ' A ', + ' For ', + ' In ', + ' Of ', + ' The ', + ' To ', + ] + for word in smallwords: + s = s.replace(word, word.lower()) + return s try: import textwrap @@ -678,8 +690,9 @@ class Card: outstr += ' '.join(map(str.capitalize, self.__dict__[field_supertypes]) + basetypes) if self.__dict__[field_subtypes]: - outstr += (' ' + utils.dash_marker + ' ' + - ' '.join(self.__dict__[field_subtypes]).title()) + outstr += (' ' + utils.dash_marker) + for subtype in self.__dict__[field_subtypes]: + outstr += ' ' + titlecase(subtype) if self.__dict__[field_pt]: outstr += ' (' + utils.from_unary(self.__dict__[field_pt]) + ')' @@ -864,7 +877,10 @@ class Card: outstr += '\tsuper type: ' + ' '.join(self.__dict__[field_supertypes] + self.__dict__[field_types]).title() + '\n' if self.__dict__[field_subtypes]: - outstr += '\tsub type: ' + ' '.join(self.__dict__[field_subtypes]).title() + '\n' + outstr += ('\tsub type:') + for subtype in self.__dict__[field_subtypes]: + outstr += ' ' + titlecase(subtype) + outstr += '\n' if self.__dict__[field_pt]: ptstring = utils.from_unary(self.__dict__[field_pt]).split('/')