Codewars_Aufgabe:_VersionManager

This commit is contained in:
Julia Hauer 2026-04-06 11:17:16 +02:00
parent e4fc718168
commit a20a178eff

View File

@ -0,0 +1,47 @@
class VersionManager:
def __init__(self, version="0.0.1"):
self.version = version
if self.version == "":
self.version = "0.0.1"
self.digits = self.version.split(sep=".")
while len(self.digits) < 3:
self.digits.append("0")
if not (
self.digits[0].isdecimal()
and self.digits[1].isdecimal()
and self.digits[2].isdecimal()
):
raise Exception("Error occured while parsing version!")
self.MAJOR = int(self.digits[0])
self.MINOR = int(self.digits[1])
self.PATCH = int(self.digits[2])
self.history = []
def major(self):
self.history.append((self.MAJOR, self.MINOR, self.PATCH))
self.MAJOR += 1
self.MINOR = 0
self.PATCH = 0
return self
def minor(self):
self.history.append((self.MAJOR, self.MINOR, self.PATCH))
self.MINOR += 1
self.PATCH = 0
return self
def patch(self):
self.history.append((self.MAJOR, self.MINOR, self.PATCH))
self.PATCH += 1
return self
def rollback(self):
if len(self.history) < 1:
raise Exception("Cannot rollback!")
else:
self.MAJOR, self.MINOR, self.PATCH = self.history.pop()
return self
def release(self):
return f"{self.MAJOR}.{self.MINOR}.{self.PATCH}"