Exemplo n.º 1
0
    def _validate(self, value):
        """Validate that the value is of the correct type."""

        if type(value) is _Types.Area:
            return value._convert_to(self._unit)

        else:
            # Extract the value and unit from the argument string.
            value, unit = _validate_unit_requirement(value, "area")

            if unit is None:
                return _Types.Area(value, self._unit)
            else:
                return _Types.Area(value, unit)._convert_to(self._unit)
Exemplo n.º 2
0
    def __init__(self,
                 help=None,
                 default=None,
                 unit=None,
                 minimum=None,
                 maximum=None,
                 allowed=None):
        """Constructor.

           Parameters
           ----------

           help : str
               The help string.

           default : :class:`Area <BioSimSpace.Types.Area>`
               The default value.

           unit : str
               The unit.

           minimum : :class:`Area <BioSimSpace.Types.Area>`
               The minimum allowed value.

           maximum : :class:`Area <BioSimSpace.Types.Area>`
               The maximum allowed value.

           allowed : [:class:`Area <BioSimSpace.Types.Area>`]
               A list of allowed values.
        """

        # Validate the unit.
        if unit is not None:
            area = _Types.Area("1 %s" % unit)
            self._unit = area.unit()
            self._print_unit = area._print_format[area.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)