Class: Object::Syck::Map

Inherits:
Node show all
Defined in:
ext/syck/rubyext.c

Instance Attribute Summary

Attributes inherited from Node

#emitter, #kind, #resolver, #type_id, #value

Instance Method Summary collapse

Methods inherited from Node

#transform, #type_id=

Constructor Details

#initialize(type_id, val, style) ⇒ Object

YAML::Syck::Map.initialize



1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
# File 'ext/syck/rubyext.c', line 1717

VALUE
syck_map_initialize(VALUE self, VALUE type_id, VALUE val, VALUE style)
{
    SyckNode *node;
    TypedData_Get_Struct( self, SyckNode, &syck_node_type, 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;
}

Instance Method Details

#add(key, val) ⇒ Object

YAML::Syck::Map.add



1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
# File 'ext/syck/rubyext.c', line 1783

VALUE
syck_map_add_m(VALUE self, VALUE key, VALUE val)
{
    SyckNode *node;
    VALUE emitter = rb_ivar_get( self, s_emitter );
    TypedData_Get_Struct( self, SyckNode, &syck_node_type, 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;
}

#style=(style) ⇒ Object

YAML::Syck::Map.style=



1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
# File 'ext/syck/rubyext.c', line 1803

VALUE
syck_map_style_set(VALUE self, VALUE style)
{
    SyckNode *node;
    TypedData_Get_Struct( self, SyckNode, &syck_node_type, 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;
}

#value=(val) ⇒ Object

YAML::Syck::Map.value=



1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
# File 'ext/syck/rubyext.c', line 1751

VALUE
syck_map_value_set(VALUE self, VALUE val)
{
    SyckNode *node;
    TypedData_Get_Struct( self, SyckNode, &syck_node_type, 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;
}