MeasureBase
This class serves as a base for handling measurements and unit conversions by maintaining a value relative to a standard unit. It provides comprehensive support for arithmetic operations, comparisons, and dynamic unit attribute access based on defined aliases and conversion factors. The class also facilitates the initialization and retrieval of values in various units through a flexible keyword-based interface.
Attributes
| Attribute | Type | Description |
|---|---|---|
| STANDARD_UNIT | string = null | The name of the primary unit used as the internal reference for all calculations and storage. |
| ALIAS | dict = {} | A mapping of alternative unit names to their corresponding keys in the UNITS dictionary. |
| UNITS | dict = {} | A dictionary defining the conversion factors for all supported units relative to the standard unit. |
| LALIAS | dict = {} | A mapping of lowercase alternative unit names used for case-insensitive unit lookups. |
| standard | float | A property that provides direct access to the measurement's value in the defined standard unit. |
Constructor
Signature
def MeasureBase(
default_unit: str = None,
**kwargs: dict
)
Parameters
| Name | Type | Description |
|---|---|---|
| default_unit | str = None | An optional string to override the default unit for representation. |
| **kwargs | dict | Keyword arguments representing unit names and their corresponding values. |
Methods
default_units()
@classmethod
def default_units(
kwargs: dict
) - > object
Return the unit value and the default units specified from the given keyword arguments dictionary.
Parameters
| Name | Type | Description |
|---|---|---|
| kwargs | dict | A dictionary of unit names and their corresponding numeric values to be converted and summed. |
Returns
| Type | Description |
|---|---|
object | A tuple containing the calculated total value in standard units and the string name of the last unit processed. |
unit_attname()
@classmethod
def unit_attname(
unit_str: string
) - > string
Retrieve the unit attribute name for the given unit string.
Parameters
| Name | Type | Description |
|---|---|---|
| unit_str | string | The unit name or alias to look up. |
Returns
| Type | Description |
|---|---|
string | The normalized unit attribute name (e.g., 'm' for 'metre'). |