Class: GitBumper::Tag
- Inherits:
-
Object
- Object
- GitBumper::Tag
- Defined in:
- lib/git_bumper/tag.rb
Overview
This object represents a git tag. It expects the following format of tags:
PREFIX.MAJOR.MINOR.PATCH
It provides some methods to parse and increment version numbers.
Constant Summary collapse
- REGEX =
/\A([a-z]+)([0-9]+)\.([0-9]+)\.([0-9]+)\z/i
Instance Attribute Summary collapse
-
#major ⇒ Object
Returns the value of attribute major.
-
#minor ⇒ Object
Returns the value of attribute minor.
-
#patch ⇒ Object
Returns the value of attribute patch.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Class Method Summary collapse
-
.parse(str) ⇒ Tag
Parses a string into a Tag object.
Instance Method Summary collapse
-
#increment(part) ⇒ Object
Increments a part of the version.
-
#initialize(prefix, major, minor, patch) ⇒ Tag
constructor
A new instance of Tag.
- #to_s ⇒ String
Constructor Details
#initialize(prefix, major, minor, patch) ⇒ Tag
Returns a new instance of Tag.
30 31 32 33 34 35 |
# File 'lib/git_bumper/tag.rb', line 30 def initialize(prefix, major, minor, patch) @prefix = prefix @major = major @minor = minor @patch = patch end |
Instance Attribute Details
#major ⇒ Object
Returns the value of attribute major.
24 25 26 |
# File 'lib/git_bumper/tag.rb', line 24 def major @major end |
#minor ⇒ Object
Returns the value of attribute minor.
24 25 26 |
# File 'lib/git_bumper/tag.rb', line 24 def minor @minor end |
#patch ⇒ Object
Returns the value of attribute patch.
24 25 26 |
# File 'lib/git_bumper/tag.rb', line 24 def patch @patch end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
23 24 25 |
# File 'lib/git_bumper/tag.rb', line 23 def prefix @prefix end |
Class Method Details
.parse(str) ⇒ Tag
Parses a string into a Tag object.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/git_bumper/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, matches[2].to_i, matches[3].to_i) end |
Instance Method Details
#increment(part) ⇒ Object
Increments a part of the version.
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/git_bumper/tag.rb', line 43 def increment(part) case part when :major @major += 1 when :minor @minor += 1 when :patch @patch += 1 end end |
#to_s ⇒ String
38 39 40 |
# File 'lib/git_bumper/tag.rb', line 38 def to_s "#{prefix}#{major}.#{minor}.#{patch}" end |