Skip to content

Commit

Permalink
Add DTO documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
haimkastner committed Mar 9, 2024
1 parent af0c176 commit dc188b1
Show file tree
Hide file tree
Showing 125 changed files with 4,625 additions and 0 deletions.
37 changes: 37 additions & 0 deletions units_generator/templates/unit_template.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,30 @@ class {{ unit }}Units(Enum):
{% endfor %}

class {{ unit }}Dto:
"""
A DTO representation of a {{ unit }}

Attributes:
value (float): The value of the {{ unit }}.
unit ({{ unit }}Units): The specific unit that the {{ unit }} value is representing.
"""

def __init__(self, value: float, unit: {{ unit }}Units):
"""
Create a new DTO representation of a {{ unit }}

Parameters:
value (float): The value of the {{ unit }}.
unit ({{ unit }}Units): The specific unit that the {{ unit }} value is representing.
"""
self.value: float = value
"""
The value of the {{ unit }}
"""
self.unit: {{ unit }}Units = unit
"""
The specific unit that the {{ unit }} value is representing
"""

def to_json(self):
return {"value": self.value, "unit": self.unit.value}
Expand Down Expand Up @@ -51,10 +72,26 @@ class {{ unit }}(AbstractMeasure):
return self.__convert_from_base(unit)

def to_dto(self, hold_in_unit: {{ unit }}Units = {{ unit }}Units.{{ base_unit }}) -> {{ unit }}Dto:
"""
Get a new instance of {{ unit }} DTO representing the current unit.

:param hold_in_unit: The specific {{ unit }} unit to store the {{ unit }} value in the DTO representation.
:type hold_in_unit: {{ unit }}Units
:return: A new instance of {{ unit }}Dto.
:rtype: {{ unit }}Dto
"""
return {{ unit }}Dto(value=self.convert(hold_in_unit), unit=hold_in_unit)

@staticmethod
def from_dto({{ unit_camel_case }}_dto: {{ unit }}Dto):
"""
Obtain a new instance of {{ unit }} from a DTO unit object.

:param {{ unit_camel_case }}_dto: The {{ unit }} DTO representation.
:type {{ unit_camel_case }}_dto: {{ unit }}Dto
:return: A new instance of {{ unit }}.
:rtype: {{ unit }}
"""
return {{ unit }}({{ unit_camel_case }}_dto.value, {{ unit_camel_case }}_dto.unit)

def __convert_from_base(self, from_unit: {{ unit }}Units) -> float:
Expand Down
37 changes: 37 additions & 0 deletions unitsnet_py/units/absorbed_dose_of_ionizing_radiation.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,30 @@ class AbsorbedDoseOfIonizingRadiationUnits(Enum):


class AbsorbedDoseOfIonizingRadiationDto:
"""
A DTO representation of a AbsorbedDoseOfIonizingRadiation
Attributes:
value (float): The value of the AbsorbedDoseOfIonizingRadiation.
unit (AbsorbedDoseOfIonizingRadiationUnits): The specific unit that the AbsorbedDoseOfIonizingRadiation value is representing.
"""

def __init__(self, value: float, unit: AbsorbedDoseOfIonizingRadiationUnits):
"""
Create a new DTO representation of a AbsorbedDoseOfIonizingRadiation
Parameters:
value (float): The value of the AbsorbedDoseOfIonizingRadiation.
unit (AbsorbedDoseOfIonizingRadiationUnits): The specific unit that the AbsorbedDoseOfIonizingRadiation value is representing.
"""
self.value: float = value
"""
The value of the AbsorbedDoseOfIonizingRadiation
"""
self.unit: AbsorbedDoseOfIonizingRadiationUnits = unit
"""
The specific unit that the AbsorbedDoseOfIonizingRadiation value is representing
"""

def to_json(self):
return {"value": self.value, "unit": self.unit.value}
Expand Down Expand Up @@ -156,10 +177,26 @@ def convert(self, unit: AbsorbedDoseOfIonizingRadiationUnits) -> float:
return self.__convert_from_base(unit)

def to_dto(self, hold_in_unit: AbsorbedDoseOfIonizingRadiationUnits = AbsorbedDoseOfIonizingRadiationUnits.Gray) -> AbsorbedDoseOfIonizingRadiationDto:
"""
Get a new instance of AbsorbedDoseOfIonizingRadiation DTO representing the current unit.
:param hold_in_unit: The specific AbsorbedDoseOfIonizingRadiation unit to store the AbsorbedDoseOfIonizingRadiation value in the DTO representation.
:type hold_in_unit: AbsorbedDoseOfIonizingRadiationUnits
:return: A new instance of AbsorbedDoseOfIonizingRadiationDto.
:rtype: AbsorbedDoseOfIonizingRadiationDto
"""
return AbsorbedDoseOfIonizingRadiationDto(value=self.convert(hold_in_unit), unit=hold_in_unit)

@staticmethod
def from_dto(absorbed_dose_of_ionizing_radiation_dto: AbsorbedDoseOfIonizingRadiationDto):
"""
Obtain a new instance of AbsorbedDoseOfIonizingRadiation from a DTO unit object.
:param absorbed_dose_of_ionizing_radiation_dto: The AbsorbedDoseOfIonizingRadiation DTO representation.
:type absorbed_dose_of_ionizing_radiation_dto: AbsorbedDoseOfIonizingRadiationDto
:return: A new instance of AbsorbedDoseOfIonizingRadiation.
:rtype: AbsorbedDoseOfIonizingRadiation
"""
return AbsorbedDoseOfIonizingRadiation(absorbed_dose_of_ionizing_radiation_dto.value, absorbed_dose_of_ionizing_radiation_dto.unit)

def __convert_from_base(self, from_unit: AbsorbedDoseOfIonizingRadiationUnits) -> float:
Expand Down
37 changes: 37 additions & 0 deletions unitsnet_py/units/acceleration.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,30 @@ class AccelerationUnits(Enum):


class AccelerationDto:
"""
A DTO representation of a Acceleration
Attributes:
value (float): The value of the Acceleration.
unit (AccelerationUnits): The specific unit that the Acceleration value is representing.
"""

def __init__(self, value: float, unit: AccelerationUnits):
"""
Create a new DTO representation of a Acceleration
Parameters:
value (float): The value of the Acceleration.
unit (AccelerationUnits): The specific unit that the Acceleration value is representing.
"""
self.value: float = value
"""
The value of the Acceleration
"""
self.unit: AccelerationUnits = unit
"""
The specific unit that the Acceleration value is representing
"""

def to_json(self):
return {"value": self.value, "unit": self.unit.value}
Expand Down Expand Up @@ -142,10 +163,26 @@ def convert(self, unit: AccelerationUnits) -> float:
return self.__convert_from_base(unit)

def to_dto(self, hold_in_unit: AccelerationUnits = AccelerationUnits.MeterPerSecondSquared) -> AccelerationDto:
"""
Get a new instance of Acceleration DTO representing the current unit.
:param hold_in_unit: The specific Acceleration unit to store the Acceleration value in the DTO representation.
:type hold_in_unit: AccelerationUnits
:return: A new instance of AccelerationDto.
:rtype: AccelerationDto
"""
return AccelerationDto(value=self.convert(hold_in_unit), unit=hold_in_unit)

@staticmethod
def from_dto(acceleration_dto: AccelerationDto):
"""
Obtain a new instance of Acceleration from a DTO unit object.
:param acceleration_dto: The Acceleration DTO representation.
:type acceleration_dto: AccelerationDto
:return: A new instance of Acceleration.
:rtype: Acceleration
"""
return Acceleration(acceleration_dto.value, acceleration_dto.unit)

def __convert_from_base(self, from_unit: AccelerationUnits) -> float:
Expand Down
37 changes: 37 additions & 0 deletions unitsnet_py/units/amount_of_substance.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,30 @@ class AmountOfSubstanceUnits(Enum):


class AmountOfSubstanceDto:
"""
A DTO representation of a AmountOfSubstance
Attributes:
value (float): The value of the AmountOfSubstance.
unit (AmountOfSubstanceUnits): The specific unit that the AmountOfSubstance value is representing.
"""

def __init__(self, value: float, unit: AmountOfSubstanceUnits):
"""
Create a new DTO representation of a AmountOfSubstance
Parameters:
value (float): The value of the AmountOfSubstance.
unit (AmountOfSubstanceUnits): The specific unit that the AmountOfSubstance value is representing.
"""
self.value: float = value
"""
The value of the AmountOfSubstance
"""
self.unit: AmountOfSubstanceUnits = unit
"""
The specific unit that the AmountOfSubstance value is representing
"""

def to_json(self):
return {"value": self.value, "unit": self.unit.value}
Expand Down Expand Up @@ -163,10 +184,26 @@ def convert(self, unit: AmountOfSubstanceUnits) -> float:
return self.__convert_from_base(unit)

def to_dto(self, hold_in_unit: AmountOfSubstanceUnits = AmountOfSubstanceUnits.Mole) -> AmountOfSubstanceDto:
"""
Get a new instance of AmountOfSubstance DTO representing the current unit.
:param hold_in_unit: The specific AmountOfSubstance unit to store the AmountOfSubstance value in the DTO representation.
:type hold_in_unit: AmountOfSubstanceUnits
:return: A new instance of AmountOfSubstanceDto.
:rtype: AmountOfSubstanceDto
"""
return AmountOfSubstanceDto(value=self.convert(hold_in_unit), unit=hold_in_unit)

@staticmethod
def from_dto(amount_of_substance_dto: AmountOfSubstanceDto):
"""
Obtain a new instance of AmountOfSubstance from a DTO unit object.
:param amount_of_substance_dto: The AmountOfSubstance DTO representation.
:type amount_of_substance_dto: AmountOfSubstanceDto
:return: A new instance of AmountOfSubstance.
:rtype: AmountOfSubstance
"""
return AmountOfSubstance(amount_of_substance_dto.value, amount_of_substance_dto.unit)

def __convert_from_base(self, from_unit: AmountOfSubstanceUnits) -> float:
Expand Down
37 changes: 37 additions & 0 deletions unitsnet_py/units/amplitude_ratio.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,30 @@ class AmplitudeRatioUnits(Enum):


class AmplitudeRatioDto:
"""
A DTO representation of a AmplitudeRatio
Attributes:
value (float): The value of the AmplitudeRatio.
unit (AmplitudeRatioUnits): The specific unit that the AmplitudeRatio value is representing.
"""

def __init__(self, value: float, unit: AmplitudeRatioUnits):
"""
Create a new DTO representation of a AmplitudeRatio
Parameters:
value (float): The value of the AmplitudeRatio.
unit (AmplitudeRatioUnits): The specific unit that the AmplitudeRatio value is representing.
"""
self.value: float = value
"""
The value of the AmplitudeRatio
"""
self.unit: AmplitudeRatioUnits = unit
"""
The specific unit that the AmplitudeRatio value is representing
"""

def to_json(self):
return {"value": self.value, "unit": self.unit.value}
Expand Down Expand Up @@ -72,10 +93,26 @@ def convert(self, unit: AmplitudeRatioUnits) -> float:
return self.__convert_from_base(unit)

def to_dto(self, hold_in_unit: AmplitudeRatioUnits = AmplitudeRatioUnits.DecibelVolt) -> AmplitudeRatioDto:
"""
Get a new instance of AmplitudeRatio DTO representing the current unit.
:param hold_in_unit: The specific AmplitudeRatio unit to store the AmplitudeRatio value in the DTO representation.
:type hold_in_unit: AmplitudeRatioUnits
:return: A new instance of AmplitudeRatioDto.
:rtype: AmplitudeRatioDto
"""
return AmplitudeRatioDto(value=self.convert(hold_in_unit), unit=hold_in_unit)

@staticmethod
def from_dto(amplitude_ratio_dto: AmplitudeRatioDto):
"""
Obtain a new instance of AmplitudeRatio from a DTO unit object.
:param amplitude_ratio_dto: The AmplitudeRatio DTO representation.
:type amplitude_ratio_dto: AmplitudeRatioDto
:return: A new instance of AmplitudeRatio.
:rtype: AmplitudeRatio
"""
return AmplitudeRatio(amplitude_ratio_dto.value, amplitude_ratio_dto.unit)

def __convert_from_base(self, from_unit: AmplitudeRatioUnits) -> float:
Expand Down
37 changes: 37 additions & 0 deletions unitsnet_py/units/angle.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,30 @@ class AngleUnits(Enum):


class AngleDto:
"""
A DTO representation of a Angle
Attributes:
value (float): The value of the Angle.
unit (AngleUnits): The specific unit that the Angle value is representing.
"""

def __init__(self, value: float, unit: AngleUnits):
"""
Create a new DTO representation of a Angle
Parameters:
value (float): The value of the Angle.
unit (AngleUnits): The specific unit that the Angle value is representing.
"""
self.value: float = value
"""
The value of the Angle
"""
self.unit: AngleUnits = unit
"""
The specific unit that the Angle value is representing
"""

def to_json(self):
return {"value": self.value, "unit": self.unit.value}
Expand Down Expand Up @@ -156,10 +177,26 @@ def convert(self, unit: AngleUnits) -> float:
return self.__convert_from_base(unit)

def to_dto(self, hold_in_unit: AngleUnits = AngleUnits.Degree) -> AngleDto:
"""
Get a new instance of Angle DTO representing the current unit.
:param hold_in_unit: The specific Angle unit to store the Angle value in the DTO representation.
:type hold_in_unit: AngleUnits
:return: A new instance of AngleDto.
:rtype: AngleDto
"""
return AngleDto(value=self.convert(hold_in_unit), unit=hold_in_unit)

@staticmethod
def from_dto(angle_dto: AngleDto):
"""
Obtain a new instance of Angle from a DTO unit object.
:param angle_dto: The Angle DTO representation.
:type angle_dto: AngleDto
:return: A new instance of Angle.
:rtype: Angle
"""
return Angle(angle_dto.value, angle_dto.unit)

def __convert_from_base(self, from_unit: AngleUnits) -> float:
Expand Down
Loading

0 comments on commit dc188b1

Please sign in to comment.