add_get#
module wntr.utils.enumtools
- add_get(cls=None, *, prefix=None, abbrev=False, allow_none=True)[source]#
Decorator that will add a
get()classmethod to an enum class.- Parameters:
- Returns:
the modified class
- Return type:
class
Notes
The
getmethod behaves as follows:For an integer, the integer value will be used to select the proper member. For an
Enumobject, the object’snamewill be used, and it will be processed as a string. For a string, the method will:if
allow_noneis False, then raise a TypeError if the value is None, otherwise pass None back to calling function for processingcapitalize the string
remove leading or trailing spaces
convert interior spaces or dashes to underscores
- optionally, remove a specified prefix from a string (using
prefix, which should have a default assigned by the
wntr.utils.enumtools.add_get()function.)
- optionally, remove a specified prefix from a string (using
It will then try to get the member with the name corresponding to the converted string.
- optionally, if
abbrevis True, then the string will be truncated to the first letter, only, after trying to use the full string as passed in. The
abbrevparameter will have a default value based on how theadd_get()decorator was called on this class.
- optionally, if