<commit_before>defmodule Semver do
  @moduledoc """
  Utilities for working with [semver.org](http://semver.org)-compliant version strings.
  """

  @vsn File.read!("VERSION") |> String.strip
  @pattern ~r"""
             ^v?
             (?<major>0|[1-9]\d*)\.
             (?<minor>0|[1-9]\d*)\.
             (?<patch>0|[1-9]\d*)
             (-(?<prerelease>[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?
             (\+(?<build>[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?
             $
             """x

  defstruct major: 0, minor: 0, patch: 0, prerelease: [], build: []

  @doc """
  Gets the version string of the module.
  """
  def version, do: @vsn

  @doc """
  Validates that `version` is a valid Semver string.
  """
  def is_valid(version), do: version =~ @pattern

  @doc """
  Parses `version` into a `Semver` struct.
  """
  def parse(version) do
    cond do
      is_valid(version) -> parse_valid(version)
      true -> {:error, :invalid}
    end
  end

  @doc """
  Parses a version string into a `Semver` struct. If `version` is not a valid version string, it
  raises `Semver.Error`.
  """
  def parse!(version) do
    case parse(version) do
      {:ok, retval} -> retval
      {:error, :invalid} -> raise Semver.Error, message: "Invalid version text: #{version}"
    end
  end

  @doc """
  Converts a `Semver` struct into a version string.
  """
  def to_string(struct) do<commit_msg>Add specs for all public functions<commit_after>defmodule Semver do
  @moduledoc """
  Utilities for working with [semver.org](http://semver.org)-compliant version strings.
  """

  @vsn File.read!("VERSION") |> String.strip
  @pattern ~r"""
             ^v?
             (?<major>0|[1-9]\d*)\.
             (?<minor>0|[1-9]\d*)\.
             (?<patch>0|[1-9]\d*)
             (-(?<prerelease>[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?
             (\+(?<build>[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*))?
             $
             """x

  @type t :: %Semver{major: integer, minor: integer, patch: integer, prerelease: [String.t], build: [String.t]}
  defstruct major: 0, minor: 0, patch: 0, prerelease: [], build: []

  @doc """
  Gets the version string of the module.
  """
  @spec version() :: String.t
  def version, do: @vsn

  @doc """
  Validates that `version` is a valid Semver string.
  """
  @spec is_valid(String.t) :: boolean
  def is_valid(version), do: version =~ @pattern

  @doc """
  Parses `version` into a `Semver` struct.
  """
  @spec parse(String.t) :: {:ok, t} | {:error, :invalid}
  def parse(version) do
    cond do
      is_valid(version) -> parse_valid(version)
      true -> {:error, :invalid}
    end
  end

  @doc """
  Parses a version string into a `Semver` struct. If `version` is not a valid version string, it
  raises `Semver.Error`.
  """
  @spec parse!(String.t) :: t | no_return
  def parse!(version) do
    case parse(version) do
      {:ok, retval} -> retval
      {:error, :invalid} -> raise Semver.Error, message: "Invalid version text: #{version}"
    end
  end

  @doc """
  Converts a `Semver` struct into a version string.
  """
  @spec to_string(t) :: String.t
  def to_string(struct) do
{'fraction_non_alphanumeric': 0.187399549983928, 'fraction_numerical': 0.01285760205721633, 'mean_word_length': 2.520361990950226, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2168901', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1103, 'n_words': 293}