Sha256: 622a795007790b7a2c37560df71e0bac82522a9067e93475a4ad28c468e6ef92

Contents?: true

Size: 975 Bytes

Versions: 2

Compression:

Stored size: 975 Bytes

Contents

module GitBumper
  # This object represents a "build" tag. These tags are expected to have the
  # format PREFIX.BUILD_NUMBER (e.g. v1, v2, a1, a2).
  # It provides some methods to parse, increment and compare tags.
  class BuildTag
    REGEX = /\A([a-z]+)([0-9]+)\z/i

    # Parses a string into a BuildTag object.
    #
    # @param str [String]
    # @return [BuildTag] or false if str has an invalid format
    def self.parse(str)
      matches = str.scan(REGEX).flatten

      return false if matches.empty?

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

    attr_reader :prefix
    attr_accessor :build

    # @param prefix [String]
    # @param build [Fixnum]
    def initialize(prefix, build)
      @prefix = prefix
      @build = build
    end

    # @return [String]
    def to_s
      "#{prefix}#{build}"
    end

    # Increments the build number.
    def increment(*)
      @build += 1
    end

    def <=>(other)
      build <=> other.build
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
git_bumper-0.1.4 lib/git_bumper/build_tag.rb
git_bumper-0.1.3 lib/git_bumper/build_tag.rb