Sha256: fbd4c8d1cbc5095d0a2f18af0ffd3bb76494d48c3e16f9bdda8a7dfafc9a161b

Contents?: true

Size: 902 Bytes

Versions: 2

Compression:

Stored size: 902 Bytes

Contents

module GitBumper
  # This object represents a git build tag. It expects the following format of
  # tags:
  #   PREFIX.BUILD_NUMBER
  # It provides some methods to parse and increment build numbers.
  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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
git_bumper-0.1.2 lib/git_bumper/build_tag.rb
git_bumper-0.1.1 lib/git_bumper/build_tag.rb