Sha256: fe6c738e757b0f549077c9e4c0a1c4350f8a039d6c50382dc5713f9a7c32a6e5

Contents?: true

Size: 819 Bytes

Versions: 1

Compression:

Stored size: 819 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
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
git_bumper-0.1.0 lib/git_bumper/build_tag.rb