Class: VersionManager::ReleaseVersion
- Inherits:
-
Object
- Object
- VersionManager::ReleaseVersion
- Includes:
- Comparable
- Defined in:
- lib/version-manager/release_version.rb
Defined Under Namespace
Classes: IncorrentFormat
Instance Attribute Summary collapse
-
#major ⇒ Object
readonly
Returns the value of attribute major.
-
#minor ⇒ Object
readonly
Returns the value of attribute minor.
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
-
#patch ⇒ Object
readonly
Returns the value of attribute patch.
-
#special ⇒ Object
readonly
Returns the value of attribute special.
Class Method Summary collapse
Instance Method Summary collapse
- #-(other_version) ⇒ Object
- #<=>(other_version) ⇒ Object
- #branch ⇒ Object
- #bump_major ⇒ Object
- #bump_minor ⇒ Object
- #bump_patch ⇒ Object
-
#initialize(*version_input) ⇒ ReleaseVersion
constructor
A new instance of ReleaseVersion.
- #short_version ⇒ Object
- #to_str ⇒ Object (also: #to_s)
Constructor Details
#initialize(*version_input) ⇒ ReleaseVersion
Returns a new instance of ReleaseVersion.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/version-manager/release_version.rb', line 11 def initialize(*version_input) version_components = Array(version_input.dup.flatten) if version_components.size == 1 version_components = version_components.first.scan(/(\d+)\.{1}(\d+)\.?(\d*)(?:--(\w+))?/).flatten raise ArgumentError, 'Incorrect version format' if version_components.all?(&:nil?) || version_components.empty? end @major, @minor, @patch = version_components[0..2].map(&:to_i) @special = version_components[3] recalculate_parts end |
Instance Attribute Details
#major ⇒ Object (readonly)
Returns the value of attribute major.
64 65 66 |
# File 'lib/version-manager/release_version.rb', line 64 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
64 65 66 |
# File 'lib/version-manager/release_version.rb', line 64 def minor @minor end |
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
64 65 66 |
# File 'lib/version-manager/release_version.rb', line 64 def parts @parts end |
#patch ⇒ Object (readonly)
Returns the value of attribute patch.
64 65 66 |
# File 'lib/version-manager/release_version.rb', line 64 def patch @patch end |
#special ⇒ Object (readonly)
Returns the value of attribute special.
64 65 66 |
# File 'lib/version-manager/release_version.rb', line 64 def special @special end |
Class Method Details
.valid?(version) ⇒ Boolean
58 59 60 61 62 |
# File 'lib/version-manager/release_version.rb', line 58 def self.valid?(version) new(version) && true rescue ArgumentError false end |
Instance Method Details
#-(other_version) ⇒ Object
42 43 44 |
# File 'lib/version-manager/release_version.rb', line 42 def -(other_version) self.class.new(parts.zip(other_version.parts).map { |x, y| x - y }) end |
#<=>(other_version) ⇒ Object
36 37 38 39 40 |
# File 'lib/version-manager/release_version.rb', line 36 def <=>(other_version) parts.zip(other_version.parts). map { |this, other| this <=> other }. find { |res| res != 0 } || 0 end |
#branch ⇒ Object
32 33 34 |
# File 'lib/version-manager/release_version.rb', line 32 def branch VersionManager.[:version_name].call(self) end |
#bump_major ⇒ Object
46 47 48 |
# File 'lib/version-manager/release_version.rb', line 46 def bump_major self.class.new(@major + 1, 0, 0) end |
#bump_minor ⇒ Object
50 51 52 |
# File 'lib/version-manager/release_version.rb', line 50 def bump_minor self.class.new(@major, @minor + 1, 0) end |
#bump_patch ⇒ Object
54 55 56 |
# File 'lib/version-manager/release_version.rb', line 54 def bump_patch self.class.new(@major, @minor, @patch + 1) end |
#short_version ⇒ Object
28 29 30 |
# File 'lib/version-manager/release_version.rb', line 28 def short_version [major, minor].map(&:to_i).join('.') end |
#to_str ⇒ Object Also known as: to_s
22 23 24 25 |
# File 'lib/version-manager/release_version.rb', line 22 def to_str res = parts.map(&:to_i).join('.') [res, special].compact.join('--') end |