Sha256: 19aae978673eeecdc5f0069c1a2b07f34eff0b2295d388f9af918d04eceb4d33

Contents?: true

Size: 653 Bytes

Versions: 7

Compression:

Stored size: 653 Bytes

Contents

module UniversaTools
  class SemanticVersion
    attr :parts
    include Comparable

    def initialize string
      @parts = string.split('.').map(&:to_i)
      @parts.any? { |x| x < 0 } and raise ArgumentError, "version numbers must be positive"
    end

    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

    def to_s
      @str ||= parts.join('.')
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
universa_tools-0.1.7 lib/universa_tools/semantic_version.rb
universa_tools-0.1.6 lib/universa_tools/semantic_version.rb
universa_tools-0.1.5 lib/universa_tools/semantic_version.rb
universa_tools-0.1.4 lib/universa_tools/semantic_version.rb
universa_tools-0.1.3 lib/universa_tools/semantic_version.rb
universa_tools-0.1.2 lib/universa_tools/semantic_version.rb
universa_tools-0.1.1 lib/universa_tools/semantic_version.rb