Add support to get_numbered_name() for omitting the article for single items

This commit is contained in:
Chiizujin 2024-04-01 15:51:39 +11:00
parent a9e8042bbe
commit f4cb272e22
2 changed files with 11 additions and 0 deletions

View file

@ -1476,6 +1476,7 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
method is used.
return_string (bool): If `True`, return only the singular form if count is 0,1 or
the plural form otherwise. If `False` (default), return both forms as a tuple.
no_article (bool): If `True`, do not return an article if `count` is 1.
Returns:
tuple: This is a tuple `(str, str)` with the singular and plural forms of the key
@ -1505,6 +1506,11 @@ class DefaultObject(ObjectDB, metaclass=TypeclassBase):
# look at 'an egg'.
self.aliases.add(singular, category=plural_category)
if kwargs.get("no_article") and count == 1:
if kwargs.get("return_string"):
return key
return key, key
if kwargs.get("return_string"):
return singular if count==1 else plural

View file

@ -185,6 +185,11 @@ class DefaultObjectTest(BaseEvenniaTest):
pattern,
)
def test_get_name_without_article(self):
self.assertEqual(self.obj1.get_numbered_name(1, self.char1, return_string=True), "an Obj")
self.assertEqual(
self.obj1.get_numbered_name(1, self.char1, return_string=True, no_article=True), "Obj"
)
class TestObjectManager(BaseEvenniaTest):
"Test object manager methods"