Instance Method Details

#add_from_hash(children) ⇒ Array

This method is used in conjunction with from_hash to provide a convenient
way of building and inserting child nodes present in a Ruby hashes.

This method will instantiate a node instance for each top- level key of the
input hash, to be inserted as children of the receiver instance.

Nested hashes are expected and further child nodes will be created and
added accordingly. If a hash key is a single value that value will be used
as the name for the node. If a hash key is an Array, both node name and
content will be populated.

A leaf element of the tree should be represented as a hash key with
corresponding value nil or {}.

# File 'lib/tree/utils/hash_converter.rb', line 142defadd_from_hash(children)raiseArgumentError,'Argument must be a type of hash'\
unlesschildren.is_a?(Hash)child_nodes=[]children.eachdo|child,grandchildren|child_node=self.class.from_hash({child=>grandchildren})child_nodes<<child_nodeself<<child_nodeendchild_nodesend