def _validate(self, value): """Validate that the value is of the correct type.""" if type(value) is _Types.Volume: return value._convert_to(self._unit) else: # Extract the value and unit from the argument string. value, unit = _validate_unit_requirement(value, "volume") if unit is None: return _Types.Volume(value, self._unit) else: return _Types.Volume(value, unit)._convert_to(self._unit)
def __init__(self, help=None, default=None, unit=None, minimum=None, maximum=None, allowed=None): """Constructor. Parameters ---------- help : str The help string. default : :class:`Volume <BioSimSpace.Types.Volume>` The default value. unit : str The unit. minimum : :class:`Volume <BioSimSpace.Types.Volume>` The minimum allowed value. maximum : :class:`Volume <BioSimSpace.Types.Volume>` The maximum allowed value. allowed : [:class:`Volume <BioSimSpace.Types.Volume>`] A list of allowed values. """ # Validate the unit. if unit is not None: volume = _Types.Volume("1 %s" % unit) self._unit = volume.unit() self._print_unit = volume._print_format[volume.unit()] else: try: self._unit = default.unit() except: raise ValueError( "No unit or default value has been specified!") # Call the base class constructor. super().__init__(help=help, default=default, unit=self._unit, minimum=minimum, maximum=maximum, allowed=allowed)