Class: VersionRecord::Version
- Inherits:
-
Object
- Object
- VersionRecord::Version
- Includes:
- Comparable
- Defined in:
- lib/version_record/version.rb
Defined Under Namespace
Classes: Parser
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.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #bump(segment = :minor) ⇒ Object
-
#initialize(version) ⇒ Version
constructor
A new instance of Version.
- #prerelease ⇒ Object
- #to_s ⇒ Object
- #to_version ⇒ Object
Constructor Details
#initialize(version) ⇒ Version
7 8 9 |
# File 'lib/version_record/version.rb', line 7 def initialize(version) @major, @minor, @patch, @prerelease = Parser.new(version.to_s).parse end |
Instance Attribute Details
#major ⇒ Object
Returns the value of attribute major.
5 6 7 |
# File 'lib/version_record/version.rb', line 5 def major @major end |
#minor ⇒ Object
Returns the value of attribute minor.
5 6 7 |
# File 'lib/version_record/version.rb', line 5 def minor @minor end |
#patch ⇒ Object
Returns the value of attribute patch.
5 6 7 |
# File 'lib/version_record/version.rb', line 5 def patch @patch end |
Instance Method Details
#<=>(other) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/version_record/version.rb', line 28 def <=>(other) return unless other.respond_to?(:to_version) other = other.to_version if same_segments?(other, :major, :minor, :patch, :prerelease) 0 elsif same_segments?(other, :major, :minor, :patch) compare_by(other, :prerelease) elsif same_segments?(other, :major, :minor) compare_by(other, :patch) elsif same_segments?(other, :major) compare_by(other, :minor) else compare_by(other, :major) end end |
#bump(segment = :minor) ⇒ Object
19 20 21 22 |
# File 'lib/version_record/version.rb', line 19 def bump(segment = :minor) send("bump_#{segment}") if [:major, :minor, :patch].include?(segment) self end |
#prerelease ⇒ Object
24 25 26 |
# File 'lib/version_record/version.rb', line 24 def prerelease @prerelease.name if @prerelease end |
#to_s ⇒ Object
11 12 13 |
# File 'lib/version_record/version.rb', line 11 def to_s "#{@major}.#{@minor}.#{@patch}#{@prerelease}" end |
#to_version ⇒ Object
15 16 17 |
# File 'lib/version_record/version.rb', line 15 def to_version self end |