class Semverve::SemanticVersion
Value object for a MAJOR.MINOR.PATCH semantic version.
Constants
- PATTERN
-
Regular expression for Semverveโs supported version format.
@return [Regexp]
Attributes
Major version number.
@return [Integer]
Minor version number.
@return [Integer]
Patch version number.
@return [Integer]
Public Class Methods
Source
# File lib/semverve/semantic_version.rb, line 63 def initialize(major:, minor:, patch:) @major = major @minor = minor @patch = patch end
Initializes a semantic version.
@param [Integer] major @param [Integer] minor @param [Integer] patch
@return [Semverve::SemanticVersion]
Source
# File lib/semverve/semantic_version.rb, line 41 def self.parse(value) match = value.to_s.match(PATTERN) unless match raise Error, "Expected a semantic version in MAJOR.MINOR.PATCH format, got #{value.inspect}." end new( major: match[:major].to_i, minor: match[:minor].to_i, patch: match[:patch].to_i ) end
Parses a value into a semantic version.
@param [#to_s] value
@return [Semverve::SemanticVersion]
Public Instance Methods
Source
# File lib/semverve/semantic_version.rb, line 94 def <=>(other) return unless other.is_a?(self.class) to_a <=> other.to_a end
Compares semantic versions by major, minor, then patch.
@param [Semverve::SemanticVersion] other
@return [Integer, nil]
Source
# File lib/semverve/semantic_version.rb, line 75 def increment(level) case level.to_sym when :major self.class.new(major: major + 1, minor: 0, patch: 0) when :minor self.class.new(major: major, minor: minor + 1, patch: 0) when :patch self.class.new(major: major, minor: minor, patch: patch + 1) else raise Error, "Unknown version increment level: #{level.inspect}." end end
Returns a new semantic version with the requested level incremented.
@param [Symbol, String] level
@return [Semverve::SemanticVersion]
Source
# File lib/semverve/semantic_version.rb, line 112 def to_a [major, minor, patch] end
Version as +[major, minor, patch]+.
@return [Array<Integer>]