def test_name_transforms(self): """Test various name / text transforms""" # Check that the article transforms correctly def roundtrip1(sString): return move_articles_to_front(move_articles_to_back(sString)) def roundtrip2(sString): return move_articles_to_back(move_articles_to_front(sString)) self.assertEqual(move_articles_to_back('AAAA'), 'AAAA') self.assertEqual(move_articles_to_back('There'), 'There') self.assertEqual(move_articles_to_front('AAAA'), 'AAAA') self.assertEqual(move_articles_to_front('There'), 'There') # Check moving articles self.assertEqual(move_articles_to_back('A thing'), 'thing, A') self.assertEqual(move_articles_to_back('An another'), 'another, An') self.assertEqual(move_articles_to_back('The ra ra ra'), 'ra ra ra, The') # Check moves reverse correctly self.assertEqual(roundtrip1('A thing'), 'A thing') self.assertEqual(roundtrip1('An another'), 'An another') self.assertEqual(roundtrip1('The ra ra ra'), 'The ra ra ra') self.assertEqual(roundtrip2('thing, A'), 'thing, A') self.assertEqual(roundtrip2('another, An'), 'another, An') self.assertEqual(roundtrip2('ra ra ra, The'), 'ra ra ra, The')
def make_alternative_json_name(oCard): """Alternative formatting for those cards that use a different convention""" # FIXME: Update this when we see how TTS handles multi-group cards sJSONName = move_articles_to_back(strip_group_from_name(oCard.name)) sJSONName = to_ascii(sJSONName) return sJSONName.lower()
def _ardb_crypt_card(self, oCardElem, oAbsCard, sSet): """Fill in name, set and advanced elements for a crypt card""" oAdvElem = SubElement(oCardElem, 'adv') oNameElem = SubElement(oCardElem, 'name') sName = move_articles_to_back(strip_group_from_name(oAbsCard.name)) if oAbsCard.level is not None: oAdvElem.text = 'Advanced' # This is a bit hackish oNameElem.text = sName.replace(' (Advanced)', '') else: oNameElem.text = sName oSetElem = SubElement(oCardElem, 'set') oSetElem.text = sSet
def _gen_library(self, dCards): """Generaten an TWDA text file library description. dCards is mapping of (card id, card name) -> card count. """ (dLib, iLibSize) = self._extract_library(dCards) dCombinedLib = self._group_sets(dLib) dTypes = self._group_types(dCombinedLib) sLib = "Library (%d cards)\n" \ % (iLibSize,) aSortedTypes = sorted(dTypes) # We shuffle master to be the first section aProcessed = set() for sTypeString in SECTION_ORDER: dCards = {} for sCandidate in aSortedTypes: if sCandidate in aProcessed: continue if sTypeString == sCandidate: dCards = dTypes[sCandidate] aProcessed.add(sCandidate) elif sCandidate.startswith(sTypeString + '/'): dCards = dTypes[sCandidate] aProcessed.add(sCandidate) else: continue iTotal = sum(dCards.values()) if sTypeString == 'Master': iTrifles = self._count_trifles(dLib) if iTrifles: sLib += "%s (%d; %d trifle)\n" % (sTypeString, iTotal, iTrifles) else: sLib += "%s (%d)\n" % (sCandidate, iTotal) else: # Sections in the library get an extra blank line sLib += '\n' sLib += "%s (%d)\n" % (sCandidate, iTotal) # library cards are also normalised fKey = lambda x: move_articles_to_back(x[0].name).lower() for oCard, iCount in sorted(dCards.items(), key=fKey): sName = normalise_card_name(oCard.name) sLib += "%dx %s\n" % (iCount, sName) return sLib
def norm_name(oCard): """Transform a card name to the ELDB equivalent""" sName = strip_group_from_name(oCard.name) sType = oCard.cardtype[0].name if oCard.level is not None: sName = sName.replace("(Advanced)", "(ADV)") # Handle annoying ELDB special cases if sName != "The Kikiyaon": sName = move_articles_to_back(sName) if sType == 'Imbued' or sName == 'Ondine "Boudicca" Sinclair': # These are quoted differently from other ELDB names sName = sName.replace('"', "'") elif sName not in SINGLE_QUOTE_NAMES: # usual ELDB quoting sName = sName.replace('"', "`") sName = sName.replace("'", "`") sName = to_ascii(sName) if 'PentexTM' in sName: sName = sName.replace('PentexTM', 'Pentex(TM)') return sName
def lackey_name(oCard, aUnique): """Escape the card name to Lackey CCG's requirements""" sName = oCard.name if oCard.level is not None: sName = sName.replace("(Advanced)", "Adv.") # Lackey uses (GX) postfix for the new vampires, but old # versions have no suffix if is_crypt_card(oCard): if sName in aUnique: sName = sName.replace('(Group ', '(G') else: sName = strip_group_from_name(sName) sName = move_articles_to_back(sName) # Lackey handles double-quotes a bit oddly, so we must as well if oCard.cardtype[0].name == 'Imbued': # Lackey only uses '' for Imbued sName = sName.replace('"', "''") else: sName = sName.replace('"', "'") # Bounce through ascii to strip accents, etc. return to_ascii(sName)
def normalise_card_name(sName): """Normalise the name as needed for the TWDA""" sName = move_articles_to_back(strip_group_from_name(sName)) return SPECIAL_NAMES.get(sName, sName)
def _crypt_sort_key(self, tItem): """Sort the crypt cards. We override the base class so we can sort by the modified name.""" return (-tItem[1][0], self._get_cap_key(tItem[0]), move_articles_to_back(tItem[0].name).lower())
def _ardb_lib_card(self, oCardElem, oAbsCard, sSet): """Fill in name and set for a library card""" oNameElem = SubElement(oCardElem, 'name') oNameElem.text = move_articles_to_back(oAbsCard.name) oSetElem = SubElement(oCardElem, 'set') oSetElem.text = sSet
def roundtrip2(sString): return move_articles_to_back(move_articles_to_front(sString))