What is YAML::Syck::Map?

J

Johannes Grassler

Hello,

I've been having loads of fun trying to work out how to de-serialize
a YAML dump of a data base I'm working with. More to the point I need to
process the YAML dump as a tree to restore child-parent relations
between objects (i.e. knowing the parent node when recreating a child
node).

Here's the relevant excerpt from my code:

| tree = YAML.parse(raw) # raw is a string holding the YAML input
| tree.children.each { |child|
| restore_object(child) }

And here's my YAML input:

| --- !yaml.org,2002:GraphLabel
| attributes:
[...]
| network_elements:
| - !yaml.org,2002:NetworkElement
| attributes:

I.e. the YAML input is a tree with one '--- !yaml.org,2002:GraphLabel'
at its root, at least if I interpret the dashes/indentation notation
right (please correct me if I'm wrong; I've only begun to familiarize
myself with YAML recently).

I want to call restore_object() on all nodes of type
!yaml.org,2002:NetworkElement. According to
<http://yaml4r.sourceforge.net/doc/page/parsing_yaml_documents.htm>
the call to YAML.parse should yield a YamlNode object that's
effectively the root of a tree I can descend into using its children()
method.

This is not so, for:

a) I do not get an object of type YamlNode but of YAML::Syck::Map

This is very mysterious critter about which little is known:

<http://www.ruby-doc.org/stdlib-1.8.6/libdoc/yaml/rdoc/classes/YAML/Syck/Node.html>

b) While said mysterious object does have a children() method that
method returns nil instead of the list of
!yaml.org,2002:NetworkElement I was expecting.

Can anyone shed some light on the issue or, better yet provide pointers to
comprehensive documentation?

For <http://yaml4r.sourceforge.net> is pretty thin on parsing YAML as
object trees, and <http://www.ruby-doc.org> is even worse (most YAML
methods are "documented" by a method prototype and a body that consists
of "[Source]").

Cheers,

Johannes
 
R

Robert Klemme

I've been having loads of fun trying to work out how to de-serialize
a YAML dump of a data base I'm working with. More to the point I need to
process the YAML dump as a tree to restore child-parent relations
between objects (i.e. knowing the parent node when recreating a child
node).

Here's the relevant excerpt from my code:

| tree = YAML.parse(raw) # raw is a string holding the YAML input
| tree.children.each { |child|
| restore_object(child) }

And here's my YAML input:

| --- !yaml.org,2002:GraphLabel
| attributes:
[...]
| network_elements:
| - !yaml.org,2002:NetworkElement
| attributes:

I.e. the YAML input is a tree with one '--- !yaml.org,2002:GraphLabel'
at its root, at least if I interpret the dashes/indentation notation
right (please correct me if I'm wrong; I've only begun to familiarize
myself with YAML recently).

I want to call restore_object() on all nodes of type
!yaml.org,2002:NetworkElement. According to
<http://yaml4r.sourceforge.net/doc/page/parsing_yaml_documents.htm>
the call to YAML.parse should yield a YamlNode object that's
effectively the root of a tree I can descend into using its children()
method.

This is not so, for:

a) I do not get an object of type YamlNode but of YAML::Syck::Map

This is very mysterious critter about which little is known:

<http://www.ruby-doc.org/stdlib-1.8.6/libdoc/yaml/rdoc/classes/YAML/Syck/Node.html>

b) While said mysterious object does have a children() method that
method returns nil instead of the list of
!yaml.org,2002:NetworkElement I was expecting.

I get this on ruby 1.9.2p180 (2011-02-18 revision 30909) [i386-cygwin]:

irb(main):015:0> s=<<XXX
irb(main):016:0" --- !yaml.org,2002:GraphLabel
irb(main):017:0" attributes:
irb(main):018:0" network_elements:
irb(main):019:0" - !yaml.org,2002:NetworkElement
irb(main):020:0" attributes:
irb(main):021:0" XXX
=> "--- !yaml.org,2002:GraphLabel \nattributes:\nnetwork_elements:\n-
!yaml.org,2002:NetworkElement\nattributes:\n"
irb(main):022:0> x=YAML.parse s
=> #<Syck::Map:0x1081a4d8>
irb(main):023:0> x
=> #<Syck::Map:0x1081a4d8>
irb(main):024:0> x.children
=> [nil, nil, nil]
Can anyone shed some light on the issue or, better yet provide pointers to
comprehensive documentation?

For<http://yaml4r.sourceforge.net> is pretty thin on parsing YAML as
object trees, and<http://www.ruby-doc.org> is even worse (most YAML
methods are "documented" by a method prototype and a body that consists
of "[Source]").

You can at least click on [Source] and see it (the source).

HTH

Kind regards

robert
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top