Class: GitBumper::BuildTag

Inherits:
Object
  • Object
show all
Defined in:
lib/git_bumper/build_tag.rb

Overview

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.

Constant Summary collapse

REGEX =
/\A([a-z]+)([0-9]+)\z/i

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prefix, build) ⇒ BuildTag

Returns a new instance of BuildTag.

Parameters:

  • prefix (String)
  • build (Fixnum)


25
26
27
28
# File 'lib/git_bumper/build_tag.rb', line 25

def initialize(prefix, build)
  @prefix = prefix
  @build = build
end

Instance Attribute Details

#buildObject

Returns the value of attribute build.



21
22
23
# File 'lib/git_bumper/build_tag.rb', line 21

def build
  @build
end

#prefixObject (readonly)

Returns the value of attribute prefix.



20
21
22
# File 'lib/git_bumper/build_tag.rb', line 20

def prefix
  @prefix
end

Class Method Details

.parse(str) ⇒ BuildTag

Parses a string into a BuildTag object.

Parameters:

  • str (String)

Returns:

  • (BuildTag)

    or false if str has an invalid format



12
13
14
15
16
17
18
# File 'lib/git_bumper/build_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)
end

Instance Method Details

#<=>(other) ⇒ Object



40
41
42
# File 'lib/git_bumper/build_tag.rb', line 40

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

#incrementObject

Increments the build number.



36
37
38
# File 'lib/git_bumper/build_tag.rb', line 36

def increment(*)
  @build += 1
end

#to_sString

Returns:

  • (String)


31
32
33
# File 'lib/git_bumper/build_tag.rb', line 31

def to_s
  "#{prefix}#{build}"
end