Class: RPM::Version
Instance Method Summary collapse
-
#<=>(other) ⇒ Number
Comparison between versions.
-
#e ⇒ Number
Access the epoch component.
-
#hash ⇒ String
Hash based on the version content.
- #initialize(*args) ⇒ Object constructor
-
#inspect ⇒ String
Inspect the version object.
-
#newer?(other) ⇒ Boolean
True if the version is newer than
other
. -
#older?(other) ⇒ Boolean
True if the version is older than
other
. -
#r ⇒ String
Access the release component.
-
#to_s ⇒ String
String representation in the form “v-r”.
-
#to_vre ⇒ String
String representation in the form “e:v-r”.
-
#v ⇒ String
Access the version component.
Constructor Details
#new(vr, e = nil) ⇒ Version #new(v, r, e = nil) ⇒ Version
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'ext/rpm/version.c', line 104
static VALUE
version_initialize(int argc, VALUE* argv, VALUE ver)
{
VALUE v = Qnil;
VALUE r = Qnil;
VALUE e = Qnil;
switch (argc) {
case 0:
rb_raise(rb_eArgError, "argument too few(1..3)");
case 1:
if (TYPE(argv[0]) != T_STRING) {
rb_raise(rb_eTypeError, "illegal argument type");
}
version_parse(RSTRING_PTR(argv[0]), &v, &r, &e);
break;
case 2:
if (TYPE(argv[0]) != T_STRING) {
rb_raise(rb_eTypeError, "illegal argument type");
}
version_parse(RSTRING_PTR(argv[0]), &v, &r, &e);
if (e != Qnil) {
rb_raise(rb_eTypeError, "illegal argument value");
}
e = rb_Integer(argv[1]);
break;
case 3:
if (TYPE(argv[0]) != T_STRING
|| TYPE(argv[1]) != T_STRING) {
rb_raise(rb_eTypeError, "illegal argument type");
}
v = rb_str_new2(RSTRING_PTR(argv[0]));
r = rb_str_new2(RSTRING_PTR(argv[1]));
e = rb_Integer(argv[2]);
break;
default:
rb_raise(rb_eArgError, "argument too many(1..3)");
}
if (NIL_P(v) || (!NIL_P(e) && NUM2INT(e) < 0)) {
rb_raise(rb_eArgError, "illegal argument value");
}
rb_ivar_set(ver, id_v, v);
rb_ivar_set(ver, id_r, r);
rb_ivar_set(ver, id_e, e);
return ver;
}
|
Instance Method Details
#<=>(other) ⇒ Number
Comparison between versions
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'ext/rpm/version.c', line 217
VALUE
rpm_version_cmp(VALUE ver, VALUE other)
{
VALUE ve,oe;
VALUE vr,or;
VALUE vv,ov;
int sense = 0;
if (rb_obj_is_kind_of(other, rpm_cVersion) != Qtrue) {
rb_raise(rb_eTypeError, "illegal argument type");
}
ve = rb_ivar_get(ver,id_e);
oe = rb_ivar_get(other,id_e);
if (!NIL_P(ve) && NUM2INT(ve) > 0 && NIL_P(oe))
return INT2FIX(1);
else if (NIL_P(ve) && !NIL_P(oe) && NUM2INT(oe) > 0)
return INT2FIX(-1);
else if (!NIL_P(ve) && !NIL_P(oe)) {
if (NUM2INT(ve) < NUM2INT(oe))
return INT2FIX(-1);
else if (NUM2INT(ve) > NUM2INT(oe))
return INT2FIX(1);
}
vv = rb_ivar_get(ver,id_v);
ov = rb_ivar_get(other,id_v);
if (!NIL_P(vv) && NIL_P(ov)) /* XXX */
return INT2FIX(1);
else if (NIL_P(vv) && !NIL_P(ov)) /* XXX */
return INT2FIX(-1);
else if (!NIL_P(vv) && !NIL_P(ov)) {
sense = rpmvercmp(RSTRING_PTR(vv), RSTRING_PTR(ov));
if (sense)
return INT2FIX(sense);
}
vr = rb_ivar_get(ver,id_r);
or = rb_ivar_get(other,id_r);
if (!NIL_P(vr) && NIL_P(or))
return INT2FIX(1);
else if (NIL_P(vr) && !NIL_P(or))
return INT2FIX(-1);
else if (!NIL_P(vr) && !NIL_P(or)) {
sense = rpmvercmp(RSTRING_PTR(vr), RSTRING_PTR(or));
}
return INT2FIX(sense);
}
|
#e ⇒ Number
Access the epoch component
312 313 314 315 316 |
# File 'ext/rpm/version.c', line 312
VALUE
rpm_version_get_e(VALUE ver)
{
return rb_ivar_get(ver, id_e);
}
|
#hash ⇒ String
Hash based on the version content
392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
# File 'ext/rpm/version.c', line 392
VALUE
rpm_version_hash(VALUE ver)
{
long h;
VALUE v, r, e;
v = rb_ivar_get(ver, id_v);
r = rb_ivar_get(ver, id_r);
e = rb_ivar_get(ver, id_e);
h = NIL_P(e) ? 0 : NUM2INT(e);
h = (h << 1) ^ NUM2LONG(rb_hash(r));
h = (h << 1) ^ NUM2LONG(rb_hash(v));
return LONG2FIX(h);
}
|
#inspect ⇒ String
Inspect the version object
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 |
# File 'ext/rpm/version.c', line 369
VALUE
rpm_version_inspect(VALUE ver)
{
char buf[BUFSIZ];
VALUE v, r, e;
v = rb_ivar_get(ver, id_v);
r = rb_ivar_get(ver, id_r);
e = rb_ivar_get(ver, id_e);
if (!NIL_P(e)) {
snprintf(buf, BUFSIZ, "#<RPM::Version v=%s, r=%s, e=%ld>", RSTRING_PTR(rb_inspect(v)), RSTRING_PTR(rb_inspect(r)), (long) NUM2INT(e));
} else {
snprintf(buf, BUFSIZ, "#<RPM::Version v=%s, r=%s>", RSTRING_PTR(rb_inspect(v)), RSTRING_PTR(rb_inspect(r)));
}
return rb_str_new2(buf);
}
|
#newer?(other) ⇒ Boolean
Returns true if the version is newer than other
.
270 271 272 273 274 |
# File 'ext/rpm/version.c', line 270
VALUE
rpm_version_is_newer(VALUE ver, VALUE other)
{
return (NUM2INT(rpm_version_cmp(ver, other)) > 0) ? Qtrue : Qfalse;
}
|
#older?(other) ⇒ Boolean
Returns true if the version is older than other
.
280 281 282 283 284 |
# File 'ext/rpm/version.c', line 280
VALUE
rpm_version_is_older(VALUE ver, VALUE other)
{
return rpm_version_is_newer(ver, other) ? Qfalse : Qtrue;
}
|
#r ⇒ String
Access the release component
301 302 303 304 305 |
# File 'ext/rpm/version.c', line 301
VALUE
rpm_version_get_r(VALUE ver)
{
return rb_ivar_get(ver, id_r);
}
|
#to_s ⇒ String
Note:
The epoch is not included
String representation in the form “v-r”
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
# File 'ext/rpm/version.c', line 323
VALUE
rpm_version_to_s(VALUE ver)
{
char buf[BUFSIZ];
char *p = buf;
VALUE v, r;
v = rb_ivar_get(ver, id_v);
r = rb_ivar_get(ver, id_r);
strcpy(p, RSTRING_PTR(v));
if (!NIL_P(r)) {
strcat(p, "-");
strcat(p, RSTRING_PTR(r));
}
return rb_str_new2(buf);
}
|
#to_vre ⇒ String
Note:
The epoch is included
String representation in the form “e:v-r”
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
# File 'ext/rpm/version.c', line 344
VALUE
rpm_version_to_vre(VALUE ver)
{
char buf[BUFSIZ];
char *p = buf;
VALUE v, r, e;
v = rb_ivar_get(ver, id_v);
r = rb_ivar_get(ver, id_r);
e = rb_ivar_get(ver, id_e);
if (!NIL_P(e)) {
snprintf(buf,BUFSIZ,"%ld:", (long) NUM2INT(e));
p += strlen(buf);
}
strcpy(p, RSTRING_PTR(v));
if (!NIL_P(r)) {
strcat(p, "-");
strcat(p, RSTRING_PTR(r));
}
return rb_str_new2(buf);
}
|
#v ⇒ String
Access the version component
290 291 292 293 294 |
# File 'ext/rpm/version.c', line 290
VALUE
rpm_version_get_v(VALUE ver)
{
return rb_ivar_get(ver, id_v);
}
|