Class: Mixlib::Versioning::Format::PartialSemVer

Inherits:
Mixlib::Versioning::Format show all
Defined in:
lib/mixlib/versioning/format/partial_semver.rb

Overview

Handles partial version strings.


“`text MAJOR MAJOR.MINOR “`

EXAMPLES


“`text 11 11.0 “`

Author:

Constant Summary collapse

PARTIAL_REGEX =
/^(\d+)\.?(?:(\d*))$/

Instance Attribute Summary

Attributes inherited from Mixlib::Versioning::Format

#build, #input, #iteration, #major, #minor, #patch, #prerelease

Instance Method Summary collapse

Methods inherited from Mixlib::Versioning::Format

#<=>, #build?, #eql?, for, #hash, #in_same_prerelease_line?, #in_same_release_line?, #initialize, #inspect, #prerelease?, #prerelease_build?, #release?, #release_build?, #to_rubygems_string, #to_s, #to_semver_string

Constructor Details

This class inherits a constructor from Mixlib::Versioning::Format

Instance Method Details

#parse(version_string) ⇒ Object


45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/mixlib/versioning/format/partial_semver.rb', line 45

def parse(version_string)
  match = version_string.match(PARTIAL_REGEX) rescue nil

  unless match
    raise Mixlib::Versioning::ParseError, "'#{version_string}' is not a valid #{self.class} version string!"
  end

  @major, @minor = match[1..2]
  @major, @minor, @patch = [@major, @minor, @patch].map(&:to_i)

  # Partial versions do not contain these values, so we just set them to nil.
  @prerelease = nil
  @build      = nil
end