Class: RakeVersion::Version
- Inherits:
-
Object
- Object
- RakeVersion::Version
- Defined in:
- lib/rake-version/version.rb
Constant Summary collapse
- REGEXP =
/(\d+)\.(\d+)\.(\d+)(?:\-([a-z0-9\-]+(?:\.[a-z0-9\-]+)*))?(?:\+([a-z0-9\-]+(?:\.[a-z0-9\-]+)*))?/i
Instance Attribute Summary collapse
-
#build ⇒ Object
readonly
Returns the value of attribute build.
-
#major ⇒ Object
readonly
Returns the value of attribute major.
-
#minor ⇒ Object
readonly
Returns the value of attribute minor.
-
#patch ⇒ Object
readonly
Returns the value of attribute patch.
-
#prerelease ⇒ Object
readonly
Returns the value of attribute prerelease.
Instance Method Summary collapse
- #bump(type) ⇒ Object
- #from_s(s) ⇒ Object
-
#initialize ⇒ Version
constructor
A new instance of Version.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Version
Returns a new instance of Version.
13 14 15 16 17 18 19 |
# File 'lib/rake-version/version.rb', line 13 def initialize @major = 0 @minor = 0 @patch = 0 @prerelease = nil @build = nil end |
Instance Attribute Details
#build ⇒ Object (readonly)
Returns the value of attribute build.
11 12 13 |
# File 'lib/rake-version/version.rb', line 11 def build @build end |
#major ⇒ Object (readonly)
Returns the value of attribute major.
7 8 9 |
# File 'lib/rake-version/version.rb', line 7 def major @major end |
#minor ⇒ Object (readonly)
Returns the value of attribute minor.
8 9 10 |
# File 'lib/rake-version/version.rb', line 8 def minor @minor end |
#patch ⇒ Object (readonly)
Returns the value of attribute patch.
9 10 11 |
# File 'lib/rake-version/version.rb', line 9 def patch @patch end |
#prerelease ⇒ Object (readonly)
Returns the value of attribute prerelease.
10 11 12 |
# File 'lib/rake-version/version.rb', line 10 def prerelease @prerelease end |
Instance Method Details
#bump(type) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rake-version/version.rb', line 21 def bump type case type when :major @major += 1 @minor = 0 @patch = 0 when :minor @minor += 1 @patch = 0 when :patch @patch += 1 else raise BadBumpType, "Unknown version bump type #{type.inspect}. Expecting :major, :minor or :patch." end self end |
#from_s(s) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rake-version/version.rb', line 38 def from_s s s.to_s.match(REGEXP).tap do |m| raise BadVersionString, "Version '#{s}' expected to have format MAJOR.MINOR.PATCH(-PRERELEASE)(+BUILD)." if m.nil? @major = m[1].to_i @minor = m[2].to_i @patch = m[3].to_i @prerelease = m[4] @build = m[5] end self end |
#to_s ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/rake-version/version.rb', line 50 def to_s String.new.tap do |s| s << "#{@major}.#{@minor}.#{@patch}" s << "-#{@prerelease}" if @prerelease s << "+#{@build}" if @build end end |