Class: ODPI::Dpi::VersionInfo

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
ext/odpi_ext/rbdpi-version-info.c

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Object


40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'ext/odpi_ext/rbdpi-version-info.c', line 40

static VALUE version_info_initialize(int argc, VALUE *argv, VALUE self)
{
    VALUE vernum;

    if (argc == 1) {
        VALUE arg = argv[0];
        if (FIXNUM_P(arg)) {
            vernum = arg;
        } else {
            int version = 0, release = 0, update = 0, port_release = 0, port_update = 0;
            char *s = StringValueCStr(arg);
            sscanf(s, "%d.%d.%d.%d.%d", &version, &release, &update, &port_release, &port_update);
            vernum = INT2FIX(DPI_ORACLE_VERSION_TO_NUMBER(version, release, update, port_release, port_update));
        }
    } else {
        int ver;
        Check_Type(argv[0], T_FIXNUM);
        ver = FIX2INT(argv[0]) * 100000000;
        if (argc > 1) {
            Check_Type(argv[1], T_FIXNUM);
            ver += FIX2INT(argv[1]) * 1000000;
        }
        if (argc > 2) {
            Check_Type(argv[2], T_FIXNUM);
            ver += FIX2INT(argv[2]) * 10000;
        }
        if (argc > 3) {
            Check_Type(argv[3], T_FIXNUM);
            ver += FIX2INT(argv[3]) * 100;
        }
        if (argc > 4) {
            Check_Type(argv[4], T_FIXNUM);
            ver += FIX2INT(argv[4]);
        }
        vernum = INT2FIX(ver);
    }
    rb_ivar_set(self, id_at_version, vernum);
    return self;
}

Instance Method Details

#<=>(other) ⇒ Object


110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'ext/odpi_ext/rbdpi-version-info.c', line 110

static VALUE version_info_cmp(VALUE self, VALUE other)
{
    int ver = FIX2INT(rb_ivar_get(self, id_at_version));
    int other_ver;

    if (!rb_obj_is_kind_of(cVersionInfo, other)) {
        return Qnil;
    }
    other_ver = FIX2INT(rb_ivar_get(other, id_at_version));
    if (ver == other_ver) {
        return INT2FIX(0);
    }
    if (ver > other_ver) {
        return INT2FIX(1);
    }
    return INT2FIX(-1);
}

#inspectObject


80
81
82
83
84
85
86
87
88
89
90
91
# File 'ext/odpi_ext/rbdpi-version-info.c', line 80

static VALUE version_info_inspect(VALUE self)
{
    int vernum = FIX2INT(rb_ivar_get(self, id_at_version));

    return rb_sprintf("<%s: %d.%d.%d.%d.%d>",
                      rb_obj_classname(self),
                      (vernum / 100000000),
                      (vernum / 1000000) % 100,
                      (vernum / 10000) % 100,
                      (vernum / 100) % 100,
                      (vernum / 1) % 100);
}

#to_iObject


93
94
95
96
# File 'ext/odpi_ext/rbdpi-version-info.c', line 93

static VALUE version_info_to_i(VALUE self)
{
    return rb_ivar_get(self, id_at_version);
}

#to_sObject


98
99
100
101
102
103
104
105
106
107
108
# File 'ext/odpi_ext/rbdpi-version-info.c', line 98

static VALUE version_info_to_s(VALUE self)
{
    int vernum = FIX2INT(rb_ivar_get(self, id_at_version));

    return rb_sprintf("%d.%d.%d.%d.%d",
                      (vernum / 100000000),
                      (vernum / 1000000) % 100,
                      (vernum / 10000) % 100,
                      (vernum / 100) % 100,
                      (vernum / 1) % 100);
}