Sha256: db4ea8879491d6d3c37cfd357a268d63b9bc0a4dbcbe1367dd7e1ee26373c20e

Contents?: true

Size: 1.13 KB

Versions: 32

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

module Groundskeeper
  # Encapsulates semantic version manipulation and comparison.
  class SemanticVersion
    MAJOR = "major"
    MINOR = "minor"
    PATCH = "patch"
    SEMANTIC_RELEASE_TYPE = { M: MAJOR, m: MINOR, p: PATCH }.freeze

    attr_reader :major, :minor, :patch

    # :nocov:
    def self.build(version)
      return version if version.is_a?(SemanticVersion)

      new(version)
    end
    # :nocov:

    def initialize(version)
      @major, @minor, @patch = version.split(".").map(&:to_i)
    end

    def bump(release_type)
      case SEMANTIC_RELEASE_TYPE[release_type.to_sym]
      when MAJOR
        "#{major + 1}.0.0"
      when MINOR
        "#{major}.#{minor + 1}.0"
      when PATCH
        "#{major}.#{minor}.#{patch + 1}"
      end
    end

    def >(other)
      other_version = SemanticVersion.build(other)
      other_major = other_version.major

      return true if major > other_major

      return false unless major == other_major

      other_minor = other_version.minor

      return true if minor > other_minor

      minor == other_minor && patch > other_version.patch
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
groundskeeper-bitcore-0.9.0 lib/groundskeeper/semantic_version.rb
groundskeeper-bitcore-0.8.0 lib/groundskeeper/semantic_version.rb
groundskeeper-bitcore-0.7.0 lib/groundskeeper/semantic_version.rb
groundskeeper-bitcore-0.6.0 lib/groundskeeper/semantic_version.rb
groundskeeper-bitcore-0.5.0 lib/groundskeeper/semantic_version.rb
groundskeeper-bitcore-0.4.0 lib/groundskeeper/semantic_version.rb
groundskeeper-bitcore-0.3.7 lib/groundskeeper/semantic_version.rb
groundskeeper-bitcore-0.3.6 lib/groundskeeper/semantic_version.rb
groundskeeper-bitcore-0.3.5 lib/groundskeeper/semantic_version.rb
groundskeeper-bitcore-0.3.4 lib/groundskeeper/semantic_version.rb
groundskeeper-bitcore-0.3.3 lib/groundskeeper/semantic_version.rb
groundskeeper-bitcore-0.3.2 lib/groundskeeper/semantic_version.rb