class GitBumper::Tag

This object represents a common tag in the format PREFIX.MAJOR.MINOR.PATCH (e.g. v1.0.0, v2.1.3, v0.1.0). It provides some methods to parse, increment and compare tags.

Constants

REGEX

Attributes

major[RW]
minor[RW]
patch[RW]
prefix[R]

Public Class Methods

new(prefix, major, minor, patch) click to toggle source

@param prefix [String] @param major [Fixnum] @param minor [Fixnum] @param patch [Fixnum]

# File lib/git_bumper/tag.rb, line 30
def initialize(prefix, major, minor, patch)
  @prefix = prefix
  @major = major
  @minor = minor
  @patch = patch
end
parse(str) click to toggle source

Parses a string into a Tag object.

@param str [String] @return [Tag] or false if str has an invalid format

# File lib/git_bumper/tag.rb, line 12
def self.parse(str)
  matches = str.scan(REGEX).flatten

  return false if matches.empty?

  new(matches[0],
      matches[1].to_i,
      matches[2].to_i,
      matches[3].to_i)
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/git_bumper/tag.rb, line 57
def <=>(other)
  [major, minor, patch] <=> [other.major, other.minor, other.patch]
end
increment(part) click to toggle source

Increments a part of the version.

# File lib/git_bumper/tag.rb, line 43
def increment(part)
  case part
  when :major
    @major += 1
    @minor = 0
    @patch = 0
  when :minor
    @minor += 1
    @patch = 0
  when :patch
    @patch += 1
  end
end
to_s() click to toggle source

@return [String]

# File lib/git_bumper/tag.rb, line 38
def to_s
  "#{prefix}#{major}.#{minor}.#{patch}"
end