Class: RPM::Version
Instance Attribute Summary collapse
-
#e ⇒ String
readonly
The epoch component or
nil. -
#r ⇒ String
readonly
The release component or
nil. -
#v ⇒ String
readonly
The version component.
Class Method Summary collapse
-
.parse_evr(evr) ⇒ Array
Parses a “epoch:version-release” string.
Instance Method Summary collapse
-
#<=>(other) ⇒ Number
Comparison between versions.
-
#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. -
#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”.
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 |
# 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') unless 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 |
Instance Attribute Details
#e ⇒ String (readonly)
Returns the epoch component or nil.
79 80 81 |
# File 'lib/rpm/version.rb', line 79 def e @e end |
#r ⇒ String (readonly)
Returns the release component or nil.
75 76 77 |
# File 'lib/rpm/version.rb', line 75 def r @r end |
#v ⇒ String (readonly)
Returns the version component.
71 72 73 |
# File 'lib/rpm/version.rb', line 71 def v @v end |
Class Method Details
.parse_evr(evr) ⇒ Array
Parses a “epoch:version-release” string
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rpm/version.rb', line 8 def self.parse_evr(evr) raise ArgumentError, "version can't be nil" if evr.nil? version = evr epoch = nil release = nil idx = version.rindex('-') if idx release = version[idx + 1..-1] version = version[0..idx - 1] end idx = version.index(/\D/) if idx && version[idx] == ':' epoch = version[0..idx - 1] version = version[idx + 1..-1] end [epoch ? epoch.to_i : nil, version, release] end |
Instance Method Details
#<=>(other) ⇒ Number
Comparison between versions
92 93 94 95 |
# File 'lib/rpm/version.rb', line 92 def <=>(other) RPM::Utils.check_type(other, RPM::Version) RPM::C.rpmvercmp(to_vre_epoch_zero, other.to_vre_epoch_zero) end |
#hash ⇒ String
Hash based on the version content
132 133 134 135 136 |
# File 'lib/rpm/version.rb', line 132 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.
99 100 101 |
# File 'lib/rpm/version.rb', line 99 def newer?(other) self > other end |
#older?(other) ⇒ Boolean
Returns true if the version is older than other.
105 106 107 |
# File 'lib/rpm/version.rb', line 105 def older?(other) self < other end |
#to_s ⇒ Object
Alias for to_vr
126 127 128 |
# File 'lib/rpm/version.rb', line 126 def to_s to_vr end |
#to_vr ⇒ String
The epoch is not included
String representation in the form “v-r”
112 113 114 |
# File 'lib/rpm/version.rb', line 112 def to_vr @r.nil? ? @v.to_s : "#{@v}-#{@r}" end |
#to_vre(_opts = {}) ⇒ String
The epoch is included if present
String representation in the form “e:v-r”
119 120 121 122 |
# File 'lib/rpm/version.rb', line 119 def to_vre(_opts = {}) vr = to_vr @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”
141 142 143 144 |
# File 'lib/rpm/version.rb', line 141 def to_vre_epoch_zero vr = to_vr @e.nil? ? "0:#{vr}" : "#{@e}:#{vr}" end |