Class: Magick::Enum
Direct Known Subclasses
Instance Method Summary collapse
-
#<=>(other) ⇒ -1, ...
Support Comparable module in Enum.
-
#===(other) ⇒ Boolean
“Case equal” operator for Enum.
-
#initialize(sym, val) ⇒ Magick::Enum
constructor
Initialize a new Enum instance.
-
#to_i ⇒ Numeric
Return the value of an enum.
-
#to_s ⇒ String
Return the name of an enum.
-
#|(another) ⇒ Magick::Enum
Bitwise OR for enums.
Constructor Details
#initialize(sym, val) ⇒ Magick::Enum
Initialize a new Enum instance.
162 163 164 165 166 167 168 169 170 171 172 |
# File 'ext/RMagick/rmenum.c', line 162
VALUE
Enum_initialize(VALUE self, VALUE sym, VALUE val)
{
MagickEnum *magick_enum;
TypedData_Get_Struct(self, MagickEnum, &rm_enum_data_type, magick_enum);
magick_enum->id = rb_to_id(sym); /* convert symbol to ID */
magick_enum->val = NUM2INT(val);
return self;
}
|
Instance Method Details
#<=>(other) ⇒ -1, ...
Support Comparable module in Enum.
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'ext/RMagick/rmenum.c', line 196
VALUE
Enum_spaceship(VALUE self, VALUE other)
{
MagickEnum *this, *that;
if(CLASS_OF(self) != CLASS_OF(other)) {
return Qnil;
}
TypedData_Get_Struct(self, MagickEnum, &rm_enum_data_type, this);
TypedData_Get_Struct(other, MagickEnum, &rm_enum_data_type, that);
if (this->val > that->val)
{
return INT2FIX(1);
}
else if (this->val < that->val)
{
return INT2FIX(-1);
}
return INT2FIX(0);
}
|
#===(other) ⇒ Boolean
“Case equal” operator for Enum.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'ext/RMagick/rmenum.c', line 139
VALUE
Enum_case_eq(VALUE self, VALUE other)
{
if (CLASS_OF(self) == CLASS_OF(other))
{
MagickEnum *this, *that;
TypedData_Get_Struct(self, MagickEnum, &rm_enum_data_type, this);
TypedData_Get_Struct(other, MagickEnum, &rm_enum_data_type, that);
return this->val == that->val ? Qtrue : Qfalse;
}
return Qfalse;
}
|
#to_i ⇒ Numeric
Return the value of an enum.
180 181 182 183 184 185 186 187 |
# File 'ext/RMagick/rmenum.c', line 180
VALUE
Enum_to_i(VALUE self)
{
MagickEnum *magick_enum;
TypedData_Get_Struct(self, MagickEnum, &rm_enum_data_type, magick_enum);
return INT2NUM(magick_enum->val);
}
|
#to_s ⇒ String
Return the name of an enum.
255 256 257 258 259 |
# File 'ext/RMagick/rmenum.c', line 255
VALUE
Enum_to_s(VALUE self)
{
return rb_str_new2(rm_enum_to_cstr(self));
}
|
#|(another) ⇒ Magick::Enum
Bitwise OR for enums
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 |
# File 'ext/RMagick/rmenum.c', line 226
VALUE
Enum_bitwise_or(VALUE self, VALUE another)
{
VALUE new_enum, cls;
MagickEnum *this, *that, *new_enum_data;
cls = CLASS_OF(self);
if (CLASS_OF(another) != cls)
{
rb_raise(rb_eArgError, "Expected class %s but got %s", rb_class2name(cls), rb_class2name(CLASS_OF(another)));
}
new_enum = Enum_alloc(cls);
TypedData_Get_Struct(self, MagickEnum, &rm_enum_data_type, this);
TypedData_Get_Struct(another, MagickEnum, &rm_enum_data_type, that);
TypedData_Get_Struct(new_enum, MagickEnum, &rm_enum_data_type, new_enum_data);
new_enum_data->id = rb_to_id(rb_sprintf("%s|%s", rb_id2name(this->id), rb_id2name(that->id)));
new_enum_data->val = this->val | that->val;
return new_enum;
}
|