Skip to main content

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

AttributeTypeDescription
STANDARD_UNITstring = nullThe name of the primary unit used as the internal reference for all calculations and storage.
ALIASdict = {}A mapping of alternative unit names to their corresponding keys in the UNITS dictionary.
UNITSdict = {}A dictionary defining the conversion factors for all supported units relative to the standard unit.
LALIASdict = {}A mapping of lowercase alternative unit names used for case-insensitive unit lookups.
standardfloatA 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

NameTypeDescription
default_unitstr = NoneAn optional string to override the default unit for representation.
**kwargsdictKeyword 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

NameTypeDescription
kwargsdictA dictionary of unit names and their corresponding numeric values to be converted and summed.

Returns

TypeDescription
objectA 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

NameTypeDescription
unit_strstringThe unit name or alias to look up.

Returns

TypeDescription
stringThe normalized unit attribute name (e.g., 'm' for 'metre').