Class: Debendencies::Private::PackageVersion

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/debendencies/package_version.rb

Overview

Represents a package version in the format used by Debian packages. This class is only used internally to compare package versions. It’s not exposed through the public API.

Version number formats and comparison rules are defined in the Debian Policy Manual: www.debian.org/doc/debian-policy/ch-controlfields.html#version pmhahn.github.io/dpkg-compare-versions/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version_string) ⇒ PackageVersion

Returns a new instance of PackageVersion.



17
18
19
20
21
22
# File 'lib/debendencies/package_version.rb', line 17

def initialize(version_string)
  @version_string = version_string
  # Parse version into epoch, upstream_version, and debian_revision
  @epoch, version = parse_epoch(version_string)
  @upstream_version, @debian_revision = parse_upstream_and_revision(version)
end

Instance Attribute Details

#debian_revisionObject (readonly)

Returns the value of attribute debian_revision.



15
16
17
# File 'lib/debendencies/package_version.rb', line 15

def debian_revision
  @debian_revision
end

#epochObject (readonly)

Returns the value of attribute epoch.



15
16
17
# File 'lib/debendencies/package_version.rb', line 15

def epoch
  @epoch
end

#upstream_versionObject (readonly)

Returns the value of attribute upstream_version.



15
16
17
# File 'lib/debendencies/package_version.rb', line 15

def upstream_version
  @upstream_version
end

Instance Method Details

#<=>(other) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/debendencies/package_version.rb', line 24

def <=>(other)
  # Compare epoch
  result = @epoch <=> other.epoch
  return result unless result == 0

  # Compare upstream version
  result = compare_upstream_version(@upstream_version, other.upstream_version)
  return result unless result == 0

  # Compare debian revision
  compare_debian_revision(@debian_revision, other.debian_revision)
end

#to_sObject



37
38
39
# File 'lib/debendencies/package_version.rb', line 37

def to_s
  @version_string
end