Class: Bosh::Common::VersionNumber
- Inherits:
-
Object
- Object
- Bosh::Common::VersionNumber
- Includes:
- Comparable
- Defined in:
- lib/common/version_number.rb
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #components ⇒ Object
- #dev ⇒ Object
- #final? ⇒ Boolean
-
#initialize(version_value) ⇒ VersionNumber
constructor
A new instance of VersionNumber.
- #major ⇒ Object
- #minor ⇒ Object
- #next_minor ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(version_value) ⇒ VersionNumber
Returns a new instance of VersionNumber.
5 6 7 |
# File 'lib/common/version_number.rb', line 5 def initialize(version_value) @version = version_value.to_s end |
Instance Method Details
#<=>(other) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/common/version_number.rb', line 9 def <=>(other) v1 = @version v2 = other.to_s return v1 <=> v2 if [v1, v2].all? { |v| v.to_s.match(/^\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}$/) } vp1 = components vp2 = other.components [vp1.size, vp2.size].max.times do |i| result = vp1[i].to_i <=> vp2[i].to_i return result unless result == 0 end 0 end |
#components ⇒ Object
33 34 35 |
# File 'lib/common/version_number.rb', line 33 def components @version.split('.') end |
#dev ⇒ Object
49 50 51 |
# File 'lib/common/version_number.rb', line 49 def dev final? ? self.class.new("#{@version}-dev") : self end |
#final? ⇒ Boolean
41 42 43 |
# File 'lib/common/version_number.rb', line 41 def final? !@version.end_with?('-dev') end |
#major ⇒ Object
25 26 27 |
# File 'lib/common/version_number.rb', line 25 def major components[0].to_i end |
#minor ⇒ Object
29 30 31 |
# File 'lib/common/version_number.rb', line 29 def minor components[1].to_i end |
#next_minor ⇒ Object
45 46 47 |
# File 'lib/common/version_number.rb', line 45 def next_minor self.class.new("#{major}.#{minor + 1}") end |
#to_s ⇒ Object
37 38 39 |
# File 'lib/common/version_number.rb', line 37 def to_s @version end |