sh_cpl/src/sh_edraft/coding/model/version.py

45 lines
1.2 KiB
Python
Raw Normal View History

2020-11-21 12:51:05 +01:00
from typing import Optional
2020-11-26 10:45:02 +01:00
from sh_edraft.coding.model.version_enum import VersionEnum
from sh_edraft.configuration.base.configuration_model_base import ConfigurationModelBase
2020-11-21 12:51:05 +01:00
class Version(ConfigurationModelBase):
def __init__(
self,
major: int = None,
minor: int = None,
micro: float = None
):
self._major: Optional[int] = major
self._minor: Optional[int] = minor
2020-11-22 20:56:31 +01:00
self._micro: Optional[int] = micro
2020-11-21 12:51:05 +01:00
@property
def major(self) -> int:
return self._major
@property
def minor(self) -> int:
return self._minor
@property
def micro(self) -> float:
return self._micro
def to_str(self) -> str:
return f'{self._major}.{self._minor}.{self._micro}'
def from_dict(self, settings: dict):
self._major = int(settings[VersionEnum.Major.value])
self._minor = int(settings[VersionEnum.Minor.value])
2020-11-22 20:56:31 +01:00
self._micro = int(settings[VersionEnum.Micro.value])
2020-11-21 12:51:05 +01:00
def to_dict(self) -> dict:
return {
VersionEnum.Major.value: self._major,
VersionEnum.Minor.value: self._minor,
VersionEnum.Micro.value: self._micro
}