Class: PkgVersion

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

Constant Summary collapse

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version, revision) ⇒ PkgVersion

Returns a new instance of PkgVersion



18
19
20
21
# File 'brew/Library/Homebrew/pkg_version.rb', line 18

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

Instance Attribute Details

#revisionObject (readonly)

Returns the value of attribute revision



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

def revision
  @revision
end

#versionObject (readonly)

Returns the value of attribute version



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

def version
  @version
end

Class Method Details

.parse(path) ⇒ Object



12
13
14
15
16
# File 'brew/Library/Homebrew/pkg_version.rb', line 12

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

Instance Method Details

#<=>(other) ⇒ Object



36
37
38
39
40
# File 'brew/Library/Homebrew/pkg_version.rb', line 36

def <=>(other)
  return unless other.is_a?(PkgVersion)

  (version <=> other.version).nonzero? || revision <=> other.revision
end

#hashObject



43
44
45
# File 'brew/Library/Homebrew/pkg_version.rb', line 43

def hash
  version.hash ^ revision.hash
end

#head?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'brew/Library/Homebrew/pkg_version.rb', line 23

def head?
  version.head?
end

#to_sObject Also known as: to_str



27
28
29
30
31
32
33
# File 'brew/Library/Homebrew/pkg_version.rb', line 27

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