YAML::Syck::Map.initialize
VALUE
syck_map_initialize(VALUE self, VALUE type_id, VALUE val, VALUE style)
{
SyckNode *node;
Data_Get_Struct( self, SyckNode, node );
if ( !NIL_P( val ) )
{
VALUE hsh = rb_check_convert_type(val, T_HASH, "Hash", "to_hash");
VALUE keys;
int i;
if ( NIL_P(hsh) )
{
rb_raise( rb_eTypeError, "wrong argument type" );
}
keys = rb_funcall( hsh, s_keys, 0 );
for ( i = 0; i < RARRAY_LEN(keys); i++ )
{
VALUE key = rb_ary_entry(keys, i);
syck_map_add( node, key, rb_hash_aref(hsh, key) );
}
}
rb_iv_set( self, "@kind", sym_seq );
rb_funcall( self, s_type_id_set, 1, type_id );
rb_funcall( self, s_value_set, 1, val );
rb_funcall( self, s_style_set, 1, style );
return self;
}
YAML::Syck::Map.add
VALUE
syck_map_add_m(VALUE self, VALUE key, VALUE val)
{
SyckNode *node;
VALUE emitter = rb_ivar_get( self, s_emitter );
Data_Get_Struct( self, SyckNode, node );
if ( rb_respond_to( emitter, s_node_export ) ) {
key = rb_funcall( emitter, s_node_export, 1, key );
val = rb_funcall( emitter, s_node_export, 1, val );
}
syck_map_add( node, key, val );
rb_hash_aset( rb_ivar_get( self, s_value ), key, val );
return self;
}
YAML::Syck::Map.style=
VALUE
syck_map_style_set(VALUE self, VALUE style)
{
SyckNode *node;
Data_Get_Struct( self, SyckNode, node );
if ( style == sym_inline )
{
node->data.pairs->style = map_inline;
}
else
{
node->data.pairs->style = map_none;
}
rb_iv_set( self, "@style", style );
return self;
}
YAML::Syck::Map.value=
VALUE
syck_map_value_set(VALUE self, VALUE val)
{
SyckNode *node;
Data_Get_Struct( self, SyckNode, node );
if ( !NIL_P( val ) )
{
VALUE hsh = rb_check_convert_type(val, T_HASH, "Hash", "to_hash");
VALUE keys;
int i;
if ( NIL_P(hsh) )
{
rb_raise( rb_eTypeError, "wrong argument type" );
}
syck_map_empty( node );
keys = rb_funcall( hsh, s_keys, 0 );
for ( i = 0; i < RARRAY_LEN(keys); i++ )
{
VALUE key = rb_ary_entry(keys, i);
syck_map_add( node, key, rb_hash_aref(hsh, key) );
}
}
rb_iv_set( self, "@value", val );
return val;
}