From 464584e18ff07d6f62f8eea4d6787c5e93b43e0d Mon Sep 17 00:00:00 2001 From: unexcellent <> Date: Sat, 9 Nov 2024 16:13:21 +0100 Subject: [PATCH] feat: add Mass --- generate/generate_boilerplate.py | 9 +++++ quantio/quantities.py | 62 ++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) diff --git a/generate/generate_boilerplate.py b/generate/generate_boilerplate.py index 84e6962..c30dd89 100644 --- a/generate/generate_boilerplate.py +++ b/generate/generate_boilerplate.py @@ -99,6 +99,15 @@ def _generate_properties(current_class: str, units: dict[str, str]) -> list[str] "millimeters": "10**-3", "micrometers": "10**-6", }, + "Mass": { + "tonnes": "10**3", + "kilograms": "1", + "pounds": "(1 / 2.20462)", + "ounces": "(1 / 35.27396)", + "grams": "10**-3", + "milligrams": "10**-6", + "micrograms": "10**-9", + }, "Velocity": { "meters_per_second": "1", "kilometers_per_hour": "(1 / 3.6)", diff --git a/quantio/quantities.py b/quantio/quantities.py index bd0cd1a..8e2a21e 100644 --- a/quantio/quantities.py +++ b/quantio/quantities.py @@ -168,6 +168,68 @@ def micrometers(self) -> float: # --- End of auto generated part. --- +class Mass(_QuantityBase): + """A measure of resistance to acceleration.""" + + # --- This part is auto generated. Do not change manually. --- + + def __init__( + self, + tonnes: float = 0.0, + kilograms: float = 0.0, + pounds: float = 0.0, + ounces: float = 0.0, + grams: float = 0.0, + milligrams: float = 0.0, + micrograms: float = 0.0, + ) -> None: + self._base_value = 0.0 + self._base_value += tonnes * 10**3 + self._base_value += kilograms * 1 + self._base_value += pounds * (1 / 2.20462) + self._base_value += ounces * (1 / 35.27396) + self._base_value += grams * 10**-3 + self._base_value += milligrams * 10**-6 + self._base_value += micrograms * 10**-9 + + @property + def tonnes(self) -> float: + """The mass in tonnes.""" + return self._base_value / 10**3 + + @property + def kilograms(self) -> float: + """The mass in kilograms.""" + return self._base_value / 1 + + @property + def pounds(self) -> float: + """The mass in pounds.""" + return self._base_value / (1 / 2.20462) + + @property + def ounces(self) -> float: + """The mass in ounces.""" + return self._base_value / (1 / 35.27396) + + @property + def grams(self) -> float: + """The mass in grams.""" + return self._base_value / 10**-3 + + @property + def milligrams(self) -> float: + """The mass in milligrams.""" + return self._base_value / 10**-6 + + @property + def micrograms(self) -> float: + """The mass in micrograms.""" + return self._base_value / 10**-9 + + # --- End of auto generated part. --- + + class Velocity(_QuantityBase): """Distance per time."""