Class: Psych::Emitter
Direct Known Subclasses
Constant Summary
Constants inherited from Handler
Handler::EVENTS, Handler::OPTIONS
Instance Method Summary collapse
-
#alias(anchor) ⇒ Object
Emit an alias with
anchor. -
#canonical ⇒ Object
Get the output style, canonical or not.
-
#canonical=(true) ⇒ Object
Set the output style to canonical, or not.
-
#end_document(implicit) ⇒ Object
End a document emission with an
implicitending. -
#end_mapping ⇒ Object
Emit the end of a mapping.
-
#end_sequence ⇒ Object
End sequence emission.
-
#end_stream ⇒ Object
End a stream emission.
-
#indentation ⇒ Object
Get the indentation level.
-
#indentation=(level) ⇒ Object
Set the indentation level to
level. -
#Psych::Emitter.new(io, options = Psych::Emitter::OPTIONS) ⇒ Object
constructor
Create a new Psych::Emitter that writes to
io. -
#line_width ⇒ Object
Get the preferred line width.
-
#line_width=(width) ⇒ Object
Set the preferred line with to
width. -
#scalar(value, anchor, tag, plain, quoted, style) ⇒ Object
Emit a scalar with
value,anchor,tag, and aplainorquotedstring type withstyle. -
#start_document(version, tags, implicit) ⇒ Object
Start a document emission with YAML
version,tags, and animplicitstart. -
#start_mapping(anchor, tag, implicit, style) ⇒ Object
Start emitting a YAML map with
anchor,tag, animplicitstart and end, andstyle. -
#start_sequence(anchor, tag, implicit, style) ⇒ Object
Start emitting a sequence with
anchor, atag,implicitsequence start and end, along withstyle. -
#start_stream(encoding) ⇒ Object
Start a stream emission with
encoding.
Methods inherited from Handler
#empty, #event_location, #streaming?
Constructor Details
#Psych::Emitter.new(io, options = Psych::Emitter::OPTIONS) ⇒ Object
Create a new Psych::Emitter that writes to io.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'ext/psych/psych_emitter.c', line 76
static VALUE initialize(int argc, VALUE *argv, VALUE self)
{
yaml_emitter_t * emitter;
VALUE io, options;
VALUE line_width;
VALUE indent;
VALUE canonical;
TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
if (rb_scan_args(argc, argv, "11", &io, &options) == 2) {
line_width = rb_funcall(options, id_line_width, 0);
indent = rb_funcall(options, id_indentation, 0);
canonical = rb_funcall(options, id_canonical, 0);
yaml_emitter_set_width(emitter, NUM2INT(line_width));
yaml_emitter_set_indent(emitter, NUM2INT(indent));
yaml_emitter_set_canonical(emitter, Qtrue == canonical ? 1 : 0);
}
rb_ivar_set(self, id_io, io);
yaml_emitter_set_output(emitter, writer, (void *)self);
return self;
}
|
Instance Method Details
#alias(anchor) ⇒ Object
Emit an alias with anchor.
See Psych::Handler#alias
459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 |
# File 'ext/psych/psych_emitter.c', line 459
static VALUE alias(VALUE self, VALUE anchor)
{
yaml_emitter_t * emitter;
yaml_event_t event;
TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
if(!NIL_P(anchor)) {
Check_Type(anchor, T_STRING);
anchor = rb_str_export_to_enc(anchor, rb_utf8_encoding());
}
yaml_alias_event_initialize(
&event,
(yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor))
);
emit(emitter, &event);
return self;
}
|
#canonical ⇒ Object
Get the output style, canonical or not.
498 499 500 501 502 503 504 |
# File 'ext/psych/psych_emitter.c', line 498
static VALUE canonical(VALUE self)
{
yaml_emitter_t * emitter;
TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
return (emitter->canonical == 0) ? Qfalse : Qtrue;
}
|
#canonical=(true) ⇒ Object
Set the output style to canonical, or not.
484 485 486 487 488 489 490 491 492 |
# File 'ext/psych/psych_emitter.c', line 484
static VALUE set_canonical(VALUE self, VALUE style)
{
yaml_emitter_t * emitter;
TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
yaml_emitter_set_canonical(emitter, Qtrue == style ? 1 : 0);
return style;
}
|
#end_document(implicit) ⇒ Object
End a document emission with an implicit ending.
See Psych::Handler#end_document
259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'ext/psych/psych_emitter.c', line 259
static VALUE end_document(VALUE self, VALUE imp)
{
yaml_emitter_t * emitter;
yaml_event_t event;
TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
yaml_document_end_event_initialize(&event, imp ? 1 : 0);
emit(emitter, &event);
return self;
}
|
#end_mapping ⇒ Object
Emit the end of a mapping.
See Psych::Handler#end_mapping
440 441 442 443 444 445 446 447 448 449 450 451 |
# File 'ext/psych/psych_emitter.c', line 440
static VALUE end_mapping(VALUE self)
{
yaml_emitter_t * emitter;
yaml_event_t event;
TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
yaml_mapping_end_event_initialize(&event);
emit(emitter, &event);
return self;
}
|
#end_sequence ⇒ Object
End sequence emission.
See Psych::Handler#end_sequence
376 377 378 379 380 381 382 383 384 385 386 387 |
# File 'ext/psych/psych_emitter.c', line 376
static VALUE end_sequence(VALUE self)
{
yaml_emitter_t * emitter;
yaml_event_t event;
TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
yaml_sequence_end_event_initialize(&event);
emit(emitter, &event);
return self;
}
|
#end_stream ⇒ Object
End a stream emission
See Psych::Handler#end_stream
128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'ext/psych/psych_emitter.c', line 128
static VALUE end_stream(VALUE self)
{
yaml_emitter_t * emitter;
yaml_event_t event;
TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
yaml_stream_end_event_initialize(&event);
emit(emitter, &event);
return self;
}
|
#indentation ⇒ Object
Get the indentation level.
525 526 527 528 529 530 531 |
# File 'ext/psych/psych_emitter.c', line 525
static VALUE indentation(VALUE self)
{
yaml_emitter_t * emitter;
TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
return INT2NUM(emitter->best_indent);
}
|
#indentation=(level) ⇒ Object
Set the indentation level to level. The level must be less than 10 and
greater than 1.
511 512 513 514 515 516 517 518 519 |
# File 'ext/psych/psych_emitter.c', line 511
static VALUE set_indentation(VALUE self, VALUE level)
{
yaml_emitter_t * emitter;
TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
yaml_emitter_set_indent(emitter, NUM2INT(level));
return level;
}
|
#line_width ⇒ Object
Get the preferred line width.
537 538 539 540 541 542 543 |
# File 'ext/psych/psych_emitter.c', line 537
static VALUE line_width(VALUE self)
{
yaml_emitter_t * emitter;
TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
return INT2NUM(emitter->best_width);
}
|
#line_width=(width) ⇒ Object
Set the preferred line with to width.
549 550 551 552 553 554 555 556 557 |
# File 'ext/psych/psych_emitter.c', line 549
static VALUE set_line_width(VALUE self, VALUE width)
{
yaml_emitter_t * emitter;
TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
yaml_emitter_set_width(emitter, NUM2INT(width));
return width;
}
|
#scalar(value, anchor, tag, plain, quoted, style) ⇒ Object
Emit a scalar with value, anchor, tag, and a plain or quoted
string type with style.
See Psych::Handler#scalar
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'ext/psych/psych_emitter.c', line 279
static VALUE scalar(
VALUE self,
VALUE value,
VALUE anchor,
VALUE tag,
VALUE plain,
VALUE quoted,
VALUE style
) {
yaml_emitter_t * emitter;
yaml_event_t event;
rb_encoding *encoding;
TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
Check_Type(value, T_STRING);
encoding = rb_utf8_encoding();
value = rb_str_export_to_enc(value, encoding);
if(!NIL_P(anchor)) {
Check_Type(anchor, T_STRING);
anchor = rb_str_export_to_enc(anchor, encoding);
}
if(!NIL_P(tag)) {
Check_Type(tag, T_STRING);
tag = rb_str_export_to_enc(tag, encoding);
}
const char *value_ptr = StringValuePtr(value);
yaml_scalar_event_initialize(
&event,
(yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor)),
(yaml_char_t *)(NIL_P(tag) ? NULL : StringValueCStr(tag)),
(yaml_char_t*)value_ptr,
(int)RSTRING_LEN(value),
plain ? 1 : 0,
quoted ? 1 : 0,
(yaml_scalar_style_t)NUM2INT(style)
);
emit(emitter, &event);
return self;
}
|
#start_document(version, tags, implicit) ⇒ Object
Start a document emission with YAML version, tags, and an implicit
start.
See Psych::Handler#start_document
239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'ext/psych/psych_emitter.c', line 239
static VALUE start_document(VALUE self, VALUE version, VALUE tags, VALUE imp)
{
struct start_document_data data = {
.self = self,
.version = version,
.tags = tags,
.imp = imp,
.head = NULL,
};
return rb_ensure(start_document_try, (VALUE)&data, start_document_ensure, (VALUE)&data);
}
|
#start_mapping(anchor, tag, implicit, style) ⇒ Object
Start emitting a YAML map with anchor, tag, an implicit start
and end, and style.
See Psych::Handler#start_mapping
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 |
# File 'ext/psych/psych_emitter.c', line 396
static VALUE start_mapping(
VALUE self,
VALUE anchor,
VALUE tag,
VALUE implicit,
VALUE style
) {
yaml_emitter_t * emitter;
yaml_event_t event;
rb_encoding *encoding;
TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
encoding = rb_utf8_encoding();
if(!NIL_P(anchor)) {
Check_Type(anchor, T_STRING);
anchor = rb_str_export_to_enc(anchor, encoding);
}
if(!NIL_P(tag)) {
Check_Type(tag, T_STRING);
tag = rb_str_export_to_enc(tag, encoding);
}
yaml_mapping_start_event_initialize(
&event,
(yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor)),
(yaml_char_t *)(NIL_P(tag) ? NULL : StringValueCStr(tag)),
implicit ? 1 : 0,
(yaml_mapping_style_t)NUM2INT(style)
);
emit(emitter, &event);
return self;
}
|
#start_sequence(anchor, tag, implicit, style) ⇒ Object
Start emitting a sequence with anchor, a tag, implicit sequence
start and end, along with style.
See Psych::Handler#start_sequence
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
# File 'ext/psych/psych_emitter.c', line 333
static VALUE start_sequence(
VALUE self,
VALUE anchor,
VALUE tag,
VALUE implicit,
VALUE style
) {
yaml_emitter_t * emitter;
yaml_event_t event;
rb_encoding * encoding = rb_utf8_encoding();
if(!NIL_P(anchor)) {
Check_Type(anchor, T_STRING);
anchor = rb_str_export_to_enc(anchor, encoding);
}
if(!NIL_P(tag)) {
Check_Type(tag, T_STRING);
tag = rb_str_export_to_enc(tag, encoding);
}
TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
yaml_sequence_start_event_initialize(
&event,
(yaml_char_t *)(NIL_P(anchor) ? NULL : StringValueCStr(anchor)),
(yaml_char_t *)(NIL_P(tag) ? NULL : StringValueCStr(tag)),
implicit ? 1 : 0,
(yaml_sequence_style_t)NUM2INT(style)
);
emit(emitter, &event);
return self;
}
|
#start_stream(encoding) ⇒ Object
Start a stream emission with encoding
See Psych::Handler#start_stream
108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'ext/psych/psych_emitter.c', line 108
static VALUE start_stream(VALUE self, VALUE encoding)
{
yaml_emitter_t * emitter;
yaml_event_t event;
TypedData_Get_Struct(self, yaml_emitter_t, &psych_emitter_type, emitter);
Check_Type(encoding, T_FIXNUM);
yaml_stream_start_event_initialize(&event, (yaml_encoding_t)NUM2INT(encoding));
emit(emitter, &event);
return self;
}
|