Class: Object

Inherits:
BasicObject
Defined in:
(unknown)

Instance Method Summary collapse

Instance Method Details

#to_plist(format = :xml1) ⇒ Object

Converts the object to a property list representation and returns it as a string.

format can be one of :xml1 or :binary1.



370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'ext/plist/plist.c', line 370

VALUE obj_to_plist(int argc, VALUE *argv, VALUE self) {
	VALUE type;
	int count = rb_scan_args(argc, argv, "01", &type);
	if (count < 1) {
		type = id_xml;
	} else {
		type = rb_to_id(type);
	}
	CFPropertyListFormat format;
	if (type == id_xml) {
		format = kCFPropertyListXMLFormat_v1_0;
	} else if (type == id_binary) {
		format = kCFPropertyListBinaryFormat_v1_0;
	} else if (type == id_openstep) {
		format = kCFPropertyListOpenStepFormat;
	} else {
		rb_raise(rb_eArgError, "Argument 2 must be one of :xml1, :binary1, or :openstep");
		return Qnil;
	}
	CFPropertyListRef plist = convertObject(self);
	VALUE data = convertPlistToString(plist, format);
	CFRelease(plist);
	if (type == id_xml || type == id_binary) {
		str_setBlob(data, Qfalse);
	}
	return data;
}