Class: Fontconfig::ObjectSet

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
ext/fontconfig/fc_objectset.c

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.new(*args) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'ext/fontconfig/fc_objectset.c', line 37

static VALUE rb_oset_new(int argc, VALUE *argv, VALUE klass){
  VALUE optional = Qnil;
  rb_scan_args(argc, argv, "01", &optional);
  FcObjectSet* set = FcObjectSetCreate();
  if(!set)
    rb_raise(rb_eRuntimeError, "cannot create FcObjectSet");

  VALUE self = object_set_wrap(set);
  if(optional != Qnil){
    ID each = rb_intern("each");
    if(!rb_respond_to(optional, each))
      rb_raise(rb_eArgError, "parameter must be enumerable");
    rb_block_call(optional, each, 0, 0, oset_add_i, self);
  }
  return self;
}

Instance Method Details

#<<(str) ⇒ Object



26
27
28
29
30
31
# File 'ext/fontconfig/fc_objectset.c', line 26

static VALUE rb_oset_add(VALUE self, VALUE str){
  if(!FcObjectSetAdd(OSET_UNWRAP(self), StringValuePtr(str))){
    rb_raise(rb_eRuntimeError, "cannot insert into FcObjectSet");
  }
  return str;
}

#[](index) ⇒ Object



68
69
70
71
72
73
74
75
76
# File 'ext/fontconfig/fc_objectset.c', line 68

static VALUE rb_oset_at(VALUE self, VALUE index){

  int i = NUM2INT(index);
  FcObjectSet* os = OSET_UNWRAP(self);

  if(i < 0 || i >= os->nobject)
    return Qnil;
  return rb_str_new2(os->objects[i]);
}

#add(str) ⇒ Object



26
27
28
29
30
31
# File 'ext/fontconfig/fc_objectset.c', line 26

static VALUE rb_oset_add(VALUE self, VALUE str){
  if(!FcObjectSetAdd(OSET_UNWRAP(self), StringValuePtr(str))){
    rb_raise(rb_eRuntimeError, "cannot insert into FcObjectSet");
  }
  return str;
}

#eachObject



55
56
57
58
59
60
61
62
# File 'ext/fontconfig/fc_objectset.c', line 55

static VALUE rb_oset_each(VALUE self){
  int i;
  FcObjectSet* os = OSET_UNWRAP(self);
  for (i = 0; i < os->nobject; i++){
    rb_yield(rb_str_new2(os->objects[i]));
  }
  return self;
}

#sizeObject



64
65
66
# File 'ext/fontconfig/fc_objectset.c', line 64

static VALUE rb_oset_size(VALUE self){
  return INT2NUM(OSET_UNWRAP(self)->nobject);
}