Class: PkgVersion

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
Library/Homebrew/pkg_version.rb

Constant Summary

RX =
/\A(.+?)(?:_(\d+))?\z/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version, revision) ⇒ PkgVersion

Returns a new instance of PkgVersion



16
17
18
19
# File 'Library/Homebrew/pkg_version.rb', line 16

def initialize(version, revision)
  @version = version
  @revision = revision
end

Instance Attribute Details

#revisionObject (readonly)

Returns the value of attribute revision



8
9
10
# File 'Library/Homebrew/pkg_version.rb', line 8

def revision
  @revision
end

#versionObject (readonly)

Returns the value of attribute version



8
9
10
# File 'Library/Homebrew/pkg_version.rb', line 8

def version
  @version
end

Class Method Details

.parse(path) ⇒ Object



10
11
12
13
14
# File 'Library/Homebrew/pkg_version.rb', line 10

def self.parse(path)
  _, version, revision = *path.match(RX)
  version = Version.create(version)
  new(version, revision.to_i)
end

Instance Method Details

#<=>(other) ⇒ Object



34
35
36
37
# File 'Library/Homebrew/pkg_version.rb', line 34

def <=>(other)
  return unless other.is_a?(PkgVersion)
  (version <=> other.version).nonzero? || revision <=> other.revision
end

#hashObject



40
41
42
# File 'Library/Homebrew/pkg_version.rb', line 40

def hash
  version.hash ^ revision.hash
end

#head?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'Library/Homebrew/pkg_version.rb', line 21

def head?
  version.head?
end

#to_sObject Also known as: to_str



25
26
27
28
29
30
31
# File 'Library/Homebrew/pkg_version.rb', line 25

def to_s
  if revision.positive?
    "#{version}_#{revision}"
  else
    version.to_s
  end
end