File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,8 @@ Enumerations are provided for various values in order to avoid depending on stri
4848 :members:
4949 :undoc-members:
5050
51+ .. automethod :: VocationFilter.from_name
52+
5153.. autoclass :: WorldLocation
5254 :members:
5355 :undoc-members:
Original file line number Diff line number Diff line change @@ -86,6 +86,30 @@ class VocationFilter(Enum):
8686 SORCERERS = 3
8787 DRUIDS = 4
8888
89+ @classmethod
90+ def from_name (cls , name , all_fallback = True ):
91+ """Gets a vocation filter from a vocation's name.
92+
93+ Parameters
94+ ----------
95+ name: :class:`str`
96+ The name of the vocation.
97+ all_fallback: :class:`bool`
98+ Whether to return :py:attr:`ALL` if no match is found. Otherwise, ``None`` will be returned.
99+
100+ Returns
101+ -------
102+ VocationFilter, optional:
103+ The matching vocation filter.
104+ """
105+ name = name .upper ()
106+ for vocation in cls : # type: VocationFilter
107+ if vocation .name in name or vocation .name [:- 1 ] in name and vocation != cls .ALL :
108+ return vocation
109+ if all_fallback or name .upper () == "ALL" :
110+ return cls .ALL
111+ return None
112+
89113
90114class WorldLocation (BaseEnum ):
91115 """The possible physical locations for servers."""
You can’t perform that action at this time.
0 commit comments