Class: GitBumper::BuildTag
- Inherits:
-
Object
- Object
- GitBumper::BuildTag
- 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
-
#build ⇒ Object
Returns the value of attribute build.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Class Method Summary collapse
-
.parse(str) ⇒ BuildTag
Parses a string into a BuildTag object.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#increment ⇒ Object
Increments the build number.
-
#initialize(prefix, build) ⇒ BuildTag
constructor
A new instance of BuildTag.
- #to_s ⇒ String
Constructor Details
#initialize(prefix, build) ⇒ BuildTag
Returns a new instance of BuildTag.
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
#build ⇒ Object
Returns the value of attribute build.
21 22 23 |
# File 'lib/git_bumper/build_tag.rb', line 21 def build @build end |
#prefix ⇒ Object (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.
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 |
#increment ⇒ Object
Increments the build number.
36 37 38 |
# File 'lib/git_bumper/build_tag.rb', line 36 def increment(*) @build += 1 end |
#to_s ⇒ String
31 32 33 |
# File 'lib/git_bumper/build_tag.rb', line 31 def to_s "#{prefix}#{build}" end |