class RPM::Version
Public Class Methods
Source
# 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
@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"
Source
# 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
Parses a “epoch:version-release” string @return [Array] tuple [epoch, version, release]
Public Instance Methods
Source
# 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
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
Source
# File lib/rpm/version.rb, line 84 def e @e end
@return [String] the epoch component
or +nil+
Source
# 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
Hash based on the version content @return [String]
Source
# File lib/rpm/version.rb, line 106 def newer?(other) self > other end
@param [Version] other Version
to compare against @return [Boolean] true if the version is newer than other
Source
# File lib/rpm/version.rb, line 112 def older?(other) self < other end
@param [Version] other Version
to compare against @return [Boolean] true if the version is older than other
Source
# File lib/rpm/version.rb, line 78 def r @r end
@return [String] the release component
or +nil+
Source
# File lib/rpm/version.rb, line 133 def to_s to_vr end
Alias for to_vr
@see Version#to_vr
Source
# File lib/rpm/version.rb, line 119 def to_vr vr = @r.nil? ? "#{@v}" : "#{@v}-#{@r}" end
String representation in the form “v-r” @return [String] @note The epoch is not included
Source
# File lib/rpm/version.rb, line 126 def to_vre(opts={}) vr = to_vr vre = @e.nil? ? vr : "#{@e}:#{vr}" end
String representation in the form “e:v-r” @return [String] @note The epoch is included if present
Source
# File lib/rpm/version.rb, line 148 def to_vre_epoch_zero vr = to_vr vre = @e.nil? ? "0:#{vr}" : "#{@e}:#{vr}" end
String representation in the form “e:v-r” @return [String] @note The epoch is included always. As 0 if not present