Class: LibUUID::UUID
- Inherits:
-
Object
- Object
- LibUUID::UUID
- Defined in:
- ext/lib_uuid.c
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #bytes ⇒ Object
- #initialize ⇒ Object constructor
- #to_guid ⇒ Object
- #to_short_guid ⇒ Object
- #type ⇒ Object
- #variant ⇒ Object
Constructor Details
#initialize ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 |
# File 'ext/lib_uuid.c', line 123
VALUE
lib_uuid_initialize(VALUE self)
{
lib_uuid_t *s;
Data_Get_Struct(self, lib_uuid_t, s);
s->guid = s->short_guid = s->type = s->variant = 0;
rb_iv_set(self, "@bytes", rb_str_new((char *) s->uu, 16));
return self;
}
|
Class Method Details
.guid ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 |
# File 'ext/lib_uuid.c', line 99
VALUE
lib_uuid_generate_guid(VALUE class)
{
char uu_str[GUID_STRLEN];
uuid_t uu;
uuid_generate(uu);
uuid_unparse(uu, uu_str);
return rb_str_new(uu_str, GUID_STRLEN-1);
}
|
.new(*args) ⇒ Object
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/lib_uuid.c', line 50
VALUE
lib_uuid_new(unsigned int argc, VALUE *argv, VALUE class)
{
lib_uuid_t *s;
uuid_t parsed_uu;
VALUE ret;
if( argc > 1 )
rb_raise(rb_eArgError, "too many arguments");
if( argc == 0 )
uuid_generate(parsed_uu);
if( argc == 1 )
{
if( uuid_from_obj(argv[0], parsed_uu) == -1 )
return Qnil;
if( uuid_validity_check(parsed_uu) == -1 )
return Qnil;
}
s = ALLOC_N(lib_uuid_t, 1);
uuid_copy(s->uu, parsed_uu);
ret = Data_Wrap_Struct(class, NULL, lib_uuid_free, s);
rb_obj_call_init(ret, 0, 0);
return ret;
}
|
.short_guid ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 |
# File 'ext/lib_uuid.c', line 111
VALUE
lib_uuid_generate_short_guid(VALUE class)
{
char uu_str[SHORT_GUID_STRLEN];
uuid_t uu;
uuid_generate(uu);
uuid_encode64(uu, uu_str);
return rb_str_new(uu_str, SHORT_GUID_STRLEN-1);
}
|
.valid?(*args) ⇒ Boolean
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'ext/lib_uuid.c', line 80
VALUE
lib_uuid_valid(unsigned int argc, VALUE *argv, VALUE class)
{
int i;
VALUE test[1];
if( argc == 0 )
rb_raise(rb_eArgError, "too few arguments");
for( i=0 ; i<argc ; i++ )
{
test[0] = argv[i];
if( lib_uuid_new(1, test, class) == Qnil )
return Qfalse;
}
return Qtrue;
}
|
Instance Method Details
#==(other) ⇒ Object
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'ext/lib_uuid.c', line 201
VALUE
lib_uuid_equality(VALUE self, VALUE other)
{
lib_uuid_t *s, *o;
if( TYPE(self) != T_DATA || TYPE(other) != T_DATA )
return Qfalse;
Data_Get_Struct(self, lib_uuid_t, s);
Data_Get_Struct(other, lib_uuid_t, o);
if( uuid_compare(s->uu, o->uu) != 0 )
return Qfalse;
return Qtrue;
}
|
#bytes ⇒ Object
135 136 137 138 139 |
# File 'ext/lib_uuid.c', line 135
VALUE
lib_uuid_bytes(VALUE self)
{
return rb_iv_get(self, "@bytes");
}
|
#to_guid ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'ext/lib_uuid.c', line 167
VALUE
lib_uuid_to_guid(VALUE self)
{
lib_uuid_t *s;
char uu_str[GUID_STRLEN];
Data_Get_Struct(self, lib_uuid_t, s);
if( s->guid == 0 )
{
uuid_unparse(s->uu, uu_str);
s->guid = rb_str_new(uu_str, GUID_STRLEN-1);
}
return s->guid;
}
|
#to_short_guid ⇒ Object
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'ext/lib_uuid.c', line 184
VALUE
lib_uuid_to_short_guid(VALUE self)
{
lib_uuid_t *s;
char uu_str[SHORT_GUID_STRLEN];
Data_Get_Struct(self, lib_uuid_t, s);
if( s->short_guid == 0 )
{
uuid_encode64(s->uu, uu_str);
s->short_guid = rb_str_new(uu_str, SHORT_GUID_STRLEN-1);
}
return s->short_guid;
}
|
#type ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'ext/lib_uuid.c', line 141
VALUE
lib_uuid_type(VALUE self)
{
lib_uuid_t *s;
Data_Get_Struct(self, lib_uuid_t, s);
if( s->type == 0 )
s->type = INT2NUM(uuid_type(s->uu));
return s->type;
}
|
#variant ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'ext/lib_uuid.c', line 154
VALUE
lib_uuid_variant(VALUE self)
{
lib_uuid_t *s;
Data_Get_Struct(self, lib_uuid_t, s);
if( s->variant == 0 )
s->variant = INT2NUM(uuid_variant(s->uu));
return s->variant;
}
|