class RPM::Version

Public Class Methods

new(*argv) click to toggle source

@overload new(vr, e = nil)

Creates a version object from a string representation
@param [String] vr version and release in the form "v-r"
@param [Number] e epoch
@return [Version]

@overload new(v, r, e = nil)

Creates a version object from a string representation
@param [String] v version
@param [String] r release
@param [Number] e epoch
@return [Version]

@example

RPM:: Version.new "1.0.0-3"
RPM:: Version.new "1.04"
RPM:: Version.new "1.0.0-3k", 1
RPM:: Version.new "2.0.3", "5k"
# File lib/rpm/version.rb, line 46
def initialize(*argv)

  case argv.size
    when 0
      raise(ArgumentError "wrong number of arguments (0 for 1..3)")
    when 1
      RPM::Utils.check_type(argv[0], String)
      @e, @v, @r = RPM::Version.parse_evr(argv[0])
    when 2
      # (vr, e)
      RPM::Utils.check_type(argv[0], String)
      @e, @v, @r = RPM::Version.parse_evr(argv[0])
      raise(TypeError, "illegal argument value") if not e.nil?
      @e = argv[1].to_i
    when 3
      RPM::Utils.check_type(argv[0], String)
      RPM::Utils.check_type(argv[1], String)
      @v = argv[0]
      @r = argv[1]
      @e = argv[2].to_i
    else
      raise(ArgumentError "too many arguments (#{args.size} for 1..3)")
  end
end
parse_evr(evr) click to toggle source

Parses a “epoch:version-release” string @return [Array] tuple [epoch, version, release]

# File lib/rpm/version.rb, line 11
def self.parse_evr(evr)
  raise ArgumentError, "version can't be nil" if evr.nil?
  version = evr
  epoch = nil
  release = nil

  idx = version.rindex(?-)
  version, release = version[0..idx-1], version[idx+1..-1] if idx
  
  idx = version.index(/\D/)
  if (idx && version[idx] == ?:)
    epoch = version[0..idx-1]
    version = version[idx+1..-1]
  end
  return epoch ? epoch.to_i : nil, version, release
end

Public Instance Methods

<=>(other) click to toggle source

Comparison between versions @param [Version] other @return [Number] -1 if other is greater than, 0 if other is equal to,

and +1 if other is less than version.

@example

v1 = RPM::Version.new("3.0-0",1)
v2 = RPM::Version.new("3.1-0",1)
v1 <=> v2
=> -1
# File lib/rpm/version.rb, line 99
def <=>(other)
  RPM::Utils.check_type(other, RPM::Version)
  ret = RPM::C.rpmvercmp(to_vre_epoch_zero, other.to_vre_epoch_zero)
end
e() click to toggle source

@return [String] the epoch component

or +nil+
# File lib/rpm/version.rb, line 84
def e
  @e
end
hash() click to toggle source

Hash based on the version content @return [String]

# File lib/rpm/version.rb, line 139
def hash
  h = @e.nil? ? 0 : @e;
  h = (h << 1) ^ @r.hash
  h = (h << 1) ^ @v.hash
end
newer?(other) click to toggle source

@param [Version] other Version to compare against @return [Boolean] true if the version is newer than other

# File lib/rpm/version.rb, line 106
def newer?(other)
  self > other
end
older?(other) click to toggle source

@param [Version] other Version to compare against @return [Boolean] true if the version is older than other

# File lib/rpm/version.rb, line 112
def older?(other)
  self < other
end
r() click to toggle source

@return [String] the release component

or +nil+
# File lib/rpm/version.rb, line 78
def r
  @r
end
to_s() click to toggle source

Alias for to_vr @see Version#to_vr

# File lib/rpm/version.rb, line 133
def to_s
  to_vr
end
to_vr() click to toggle source

String representation in the form “v-r” @return [String] @note The epoch is not included

# File lib/rpm/version.rb, line 119
def to_vr
  vr = @r.nil? ? "#{@v}" : "#{@v}-#{@r}"
end
to_vre(opts={}) click to toggle source

String representation in the form “e:v-r” @return [String] @note The epoch is included if present

# File lib/rpm/version.rb, line 126
def to_vre(opts={})
  vr = to_vr
  vre = @e.nil? ? vr : "#{@e}:#{vr}"
end
to_vre_epoch_zero() click to toggle source

String representation in the form “e:v-r” @return [String] @note The epoch is included always. As 0 if not present

# File lib/rpm/version.rb, line 148
def to_vre_epoch_zero
  vr = to_vr
  vre = @e.nil? ? "0:#{vr}" : "#{@e}:#{vr}"
end
v() click to toggle source

@return [String] the version component

# File lib/rpm/version.rb, line 72
def v
  @v
end