Class: VersionRecord::Prerelease
- Inherits:
-
Object
- Object
- VersionRecord::Prerelease
- Includes:
- Comparable
- Defined in:
- lib/version_record/prerelease.rb
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #first_segment ⇒ Object
-
#initialize(string) ⇒ Prerelease
constructor
A new instance of Prerelease.
- #name ⇒ Object
- #tail ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(string) ⇒ Prerelease
Returns a new instance of Prerelease.
9 10 11 |
# File 'lib/version_record/prerelease.rb', line 9 def initialize(string) @string = string end |
Class Method Details
.build(string) ⇒ Object
5 6 7 |
# File 'lib/version_record/prerelease.rb', line 5 def self.build(string) new(".#{string}") if string.present? end |
Instance Method Details
#<=>(other) ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/version_record/prerelease.rb', line 29 def <=>(other) return unless other.is_a?(Prerelease) if first_segment == other.first_segment compare_by_tail(other) else compare_by_first_segment(other) end end |
#first_segment ⇒ Object
25 26 27 |
# File 'lib/version_record/prerelease.rb', line 25 def first_segment @first_segment ||= at(0) end |
#name ⇒ Object
17 18 19 |
# File 'lib/version_record/prerelease.rb', line 17 def name @string[1..-1] end |
#tail ⇒ Object
21 22 23 |
# File 'lib/version_record/prerelease.rb', line 21 def tail @tail ||= self.class.build(at(1..-1).join('.')) end |
#to_s ⇒ Object
13 14 15 |
# File 'lib/version_record/prerelease.rb', line 13 def to_s @string end |