Class: SemVer
Defined Under Namespace
Classes: InvalidVersion
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(spec) ⇒ SemVer
constructor
A new instance of SemVer.
- #inspect ⇒ Object
- #major ⇒ Object
- #minor ⇒ Object
- #patch ⇒ Object
- #prerelease ⇒ Object
- #to_s ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(spec) ⇒ SemVer
Returns a new instance of SemVer.
10 11 12 |
# File 'lib/sem_ver.rb', line 10 def initialize(spec) @spec = spec end |
Class Method Details
.parse(*args) ⇒ Object
6 7 8 |
# File 'lib/sem_ver.rb', line 6 def self.parse(*args) new(*args) end |
Instance Method Details
#<=>(other) ⇒ Object
34 35 36 37 |
# File 'lib/sem_ver.rb', line 34 def <=>(other) raise InvalidVersion.new(to_s) unless valid? && other.valid? parts <=> other.parts end |
#inspect ⇒ Object
46 47 48 |
# File 'lib/sem_ver.rb', line 46 def inspect "<#{'Invalid' unless valid?}Version: #{to_s}>" end |
#major ⇒ Object
14 15 16 |
# File 'lib/sem_ver.rb', line 14 def major match && match[1].to_i end |
#minor ⇒ Object
18 19 20 |
# File 'lib/sem_ver.rb', line 18 def minor match && match[2].to_i end |
#patch ⇒ Object
22 23 24 |
# File 'lib/sem_ver.rb', line 22 def patch match && match[3].to_i end |
#prerelease ⇒ Object
26 27 28 |
# File 'lib/sem_ver.rb', line 26 def prerelease match && match[5] end |
#to_s ⇒ Object
39 40 41 42 43 44 |
# File 'lib/sem_ver.rb', line 39 def to_s return @spec unless valid? "#{major}.#{minor}.#{patch}".tap do |v| v << "-#{prerelease}" if prerelease end end |
#valid? ⇒ Boolean
30 31 32 |
# File 'lib/sem_ver.rb', line 30 def valid? !!match end |