By the way, I’ve checked the Version module, but the version pattern doesn’t entirely comply with SemVer, so if we use it, we’ll need to handle our version before
If this is only numbers (no prereleases) then you use lists of numbers to compare. Their sort order should match what I imagine you want the versions to sort by:
How does Version do not comply with SemVer? Especially that your versions mentioned there aren’t really SemVer compatible, as have more segments than 3 (major, minor, and patch).
If you want to compare them:
def parse_ver(str) do
str
|> String.split(".")
|> Enum.map(&String.to_integer/1)
end
def compare([a | as], [b | bs]) when a == b, do: compare(as, bs)
def compare([], []), do: {:ok, :equal}
def compare([a | _], [b | _]) when a > b, do: {:ok, :greater}
def compare([a | _], [b | _]) when a < b, do: {:ok, :lesser}
def compare(_, _), do: {:error, :incomparable}