Class: RPM::Version
Class Method Summary collapse
-
.parse_evr(evr) ⇒ Array
Parses a “epoch:version-release” string.
Instance Method Summary collapse
-
#<=>(other) ⇒ Number
Comparison between versions.
-
#e ⇒ String
The epoch component or
nil
. -
#hash ⇒ String
Hash based on the version content.
-
#initialize(*argv) ⇒ Version
constructor
A new instance of Version.
-
#newer?(other) ⇒ Boolean
True if the version is newer than
other
. -
#older?(other) ⇒ Boolean
True if the version is older than
other
. -
#r ⇒ String
The release component or
nil
. -
#to_s ⇒ Object
Alias for
to_vr
. -
#to_vr ⇒ String
String representation in the form “v-r”.
-
#to_vre(opts = {}) ⇒ String
String representation in the form “e:v-r”.
-
#to_vre_epoch_zero ⇒ String
String representation in the form “e:v-r”.
-
#v ⇒ String
The version component.
Constructor Details
#new(vr, e = nil) ⇒ Version #new(v, r, e = nil) ⇒ Version
Returns a new instance of Version.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# 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 |
Class Method Details
.parse_evr(evr) ⇒ Array
Parses a “epoch:version-release” string
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# 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 |
Instance Method Details
#<=>(other) ⇒ Number
Comparison between versions
99 100 101 102 |
# 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 ⇒ String
Returns the epoch component or nil
.
84 85 86 |
# File 'lib/rpm/version.rb', line 84 def e @e end |
#hash ⇒ String
Hash based on the version content
139 140 141 142 143 |
# 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) ⇒ Boolean
Returns true if the version is newer than other
.
106 107 108 |
# File 'lib/rpm/version.rb', line 106 def newer?(other) self > other end |
#older?(other) ⇒ Boolean
Returns true if the version is older than other
.
112 113 114 |
# File 'lib/rpm/version.rb', line 112 def older?(other) self < other end |
#r ⇒ String
Returns the release component or nil
.
78 79 80 |
# File 'lib/rpm/version.rb', line 78 def r @r end |
#to_s ⇒ Object
Alias for to_vr
133 134 135 |
# File 'lib/rpm/version.rb', line 133 def to_s to_vr end |
#to_vr ⇒ String
The epoch is not included
String representation in the form “v-r”
119 120 121 |
# File 'lib/rpm/version.rb', line 119 def to_vr vr = @r.nil? ? "#{@v}" : "#{@v}-#{@r}" end |
#to_vre(opts = {}) ⇒ String
The epoch is included if present
String representation in the form “e:v-r”
126 127 128 129 |
# 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 ⇒ String
The epoch is included always. As 0 if not present
String representation in the form “e:v-r”
148 149 150 151 |
# File 'lib/rpm/version.rb', line 148 def to_vre_epoch_zero vr = to_vr vre = @e.nil? ? "0:#{vr}" : "#{@e}:#{vr}" end |
#v ⇒ String
Returns the version component.
72 73 74 |
# File 'lib/rpm/version.rb', line 72 def v @v end |