Class: RPM::Version

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
ext/rpm/version.c

Instance Method Summary (collapse)

Constructor Details

- (Version) new(vr, e = nil) - (Version) new(v, r, e = nil)

Examples:

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"

Overloads:

  • - (Version) new(vr, e = nil)

    Creates a version object from a string representation

    Parameters:

    • vr (String)

      version and release in the form "v-r"

    • e (Number)

      epoch

    Returns:

  • - (Version) new(v, r, e = nil)

    Creates a version object from a string representation

    Parameters:

    • v (String)

      version

    • r (String)

      release

    • e (Number)

      epoch

    Returns:



# File 'ext/rpm/version.c'

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");
}

Instance Method Details

- (Number) <=>

Comparison between versions

Examples:

v1 = RPM::Version.new("3.0-0",1)
v2 = RPM::Version.new("3.1-0",1)
v1 <=> v2
=> -1

Parameters:

Returns:

  • (Number)

    -1 if other is greater than, 0 if other is equal to, and +1 if other is less than version.



# File 'ext/rpm/version.c'

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");
}

- (Number) e

Access the epoch component

Returns:

  • (Number)

    epoch component or nil if the version does not have an epoch component



# File 'ext/rpm/version.c'

VALUE
rpm_version_get_e(VALUE ver)
{
    return rb_ivar_get(ver, id_e);
}

- (String) hash

Hash based on the version content

Returns:

  • (String)


# File 'ext/rpm/version.c'

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);
}

- (String) inspect

Inspect the version object

Returns:

  • (String)

    object in the form "#<RPM::Version v=V, r=R, e=E>"



# File 'ext/rpm/version.c'

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));
}

- (Boolean) newer?

True if the version is newer than other

Parameters:

  • other (Version)

    Version to compare against

Returns:

  • (Boolean)

    true if the version is newer than other



# File 'ext/rpm/version.c'

VALUE
rpm_version_is_newer(VALUE ver, VALUE other)
{
    return (NUM2INT(rpm_version_cmp(ver, other)) > 0) ? Qtrue : Qfalse;
}

- (Boolean) older?

True if the version is older than other

Parameters:

  • other (Version)

    Version to compare against

Returns:

  • (Boolean)

    true if the version is older than other



# File 'ext/rpm/version.c'

VALUE
rpm_version_is_older(VALUE ver, VALUE other)
{
    return rpm_version_is_newer(ver, other) ? Qfalse : Qtrue;
}

- (String) r

Access the release component

Returns:

  • (String)

    release component or nil if the version does not have a release component



# File 'ext/rpm/version.c'

VALUE
rpm_version_get_r(VALUE ver)
{
    return rb_ivar_get(ver, id_r);
}

- (String) to_s

Note:

The epoch is not included

String representation in the form "v-r"

Returns:

  • (String)


# File 'ext/rpm/version.c'

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));
}

- (String) to_vre

Note:

The epoch is included

String representation in the form "e:v-r"

Returns:

  • (String)


# File 'ext/rpm/version.c'

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);
}

- (String) v

Access the version component

Returns:

  • (String)

    version component



# File 'ext/rpm/version.c'

VALUE
rpm_version_get_v(VALUE ver)
{
    return rb_ivar_get(ver, id_v);
}