Class: RenuoVersion
- Inherits:
-
Object
- Object
- RenuoVersion
- Defined in:
- lib/renuo/cli/app/renuo_version.rb
Constant Summary collapse
- SEMVER_SCHEMA =
/^\d+\.\d+\.\d+(\.[a-z]+\d+)?$/
- SEGMENTS =
%w[major minor patch].freeze
Instance Attribute Summary collapse
-
#segments ⇒ Object
readonly
Returns the value of attribute segments.
Class Method Summary collapse
Instance Method Summary collapse
- #bump(segment) ⇒ Object
-
#initialize(major, minor, patch, prerelease = nil) ⇒ RenuoVersion
constructor
A new instance of RenuoVersion.
-
#prerelease? ⇒ Boolean
Returns true if it’s a release candidate (e.g. 3.0.0.rc4).
- #to_s ⇒ Object
Constructor Details
#initialize(major, minor, patch, prerelease = nil) ⇒ RenuoVersion
Returns a new instance of RenuoVersion.
15 16 17 18 |
# File 'lib/renuo/cli/app/renuo_version.rb', line 15 def initialize(major, minor, patch, prerelease = nil) @segments = [major, minor, patch].map(&:to_i) @segments.push(prerelease.to_s) if prerelease end |
Instance Attribute Details
#segments ⇒ Object (readonly)
Returns the value of attribute segments.
13 14 15 |
# File 'lib/renuo/cli/app/renuo_version.rb', line 13 def segments @segments end |
Class Method Details
.create(str) ⇒ Object
7 8 9 10 11 |
# File 'lib/renuo/cli/app/renuo_version.rb', line 7 def self.create(str) raise "Invalid segments (#{str} =~ #{SEMVER_SCHEMA})" unless SEMVER_SCHEMA.match?(str) new(*str.split(".")) end |
Instance Method Details
#bump(segment) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/renuo/cli/app/renuo_version.rb', line 20 def bump(segment) raise "Invalid segment #{segment} (must be one of #{SEGMENTS})" unless SEGMENTS.include?(segment) send(:"bump_#{segment}") self end |
#prerelease? ⇒ Boolean
Returns true if it’s a release candidate (e.g. 3.0.0.rc4)
28 29 30 |
# File 'lib/renuo/cli/app/renuo_version.rb', line 28 def prerelease? @segments.length > 3 end |
#to_s ⇒ Object
32 33 34 |
# File 'lib/renuo/cli/app/renuo_version.rb', line 32 def to_s @segments.join(".") end |