blob: 4e9e351ff0fb80a58334f72ffc1104e854843265 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
  | 
require 'version'
class PkgVersion < Version
  attr_reader :version, :revision
  RX = /\A(.+?)(?:_(\d+))?\z/
  def self.parse(path)
    _, version, revision = *path.match(RX)
    new(version, revision)
  end
  def initialize(version, revision)
    super(version)
    if head?
      @revision = 0
    else
      @revision = revision.to_i
    end
  end
  def to_s
    if revision > 0
      "#{version}_#{revision}"
    else
      version
    end
  end
  alias_method :to_str, :to_s
  def <=>(other)
    return unless Version === other
    super.nonzero? || revision <=> other.revision
  end
end
  |