Class: UniversaTools::SemanticVersion
- Inherits:
-
Object
- Object
- UniversaTools::SemanticVersion
- Includes:
- Comparable
- Defined in:
- lib/universa_tools/semantic_version.rb
Instance Attribute Summary collapse
-
#parts ⇒ Object
readonly
Returns the value of attribute parts.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
-
#initialize(string) ⇒ SemanticVersion
constructor
A new instance of SemanticVersion.
- #to_s ⇒ Object
Constructor Details
#initialize(string) ⇒ SemanticVersion
Returns a new instance of SemanticVersion.
6 7 8 9 |
# File 'lib/universa_tools/semantic_version.rb', line 6 def initialize string @parts = string.split('.').map(&:to_i) @parts.any? { |x| x < 0 } and raise ArgumentError, "version numbers must be positive" end |
Instance Attribute Details
#parts ⇒ Object (readonly)
Returns the value of attribute parts.
3 4 5 |
# File 'lib/universa_tools/semantic_version.rb', line 3 def parts @parts end |
Instance Method Details
#<=>(other) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/universa_tools/semantic_version.rb', line 11 def <=> other if other.is_a?(SemanticVersion) n = [@parts.size, other.parts.size].max (0...n).each { |i| my = @parts[i] || -1 his = other.parts[i] || -1 return my <=> his if my != his } 0 else self <=> SemanticVersion.new(other) end end |
#to_s ⇒ Object
25 26 27 |
# File 'lib/universa_tools/semantic_version.rb', line 25 def to_s @str ||= parts.join('.') end |