Sha256: be5ac7f0ef0a22766db2d29be9868d5a9224e1822da7e1dd823a212410023aa9
Contents?: true
Size: 1.19 KB
Versions: 3
Compression:
Stored size: 1.19 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 def version "#{major}.#{minor}.#{patch}" end end end
Version data entries
3 entries across 3 versions & 1 rubygems