Module: Tree::Utils::JSONConverter::ClassMethods

Defined in:
lib/tree/utils/json_converter.rb

Overview

ClassMethods for the Tree::Utils::JSONConverter module. Will become class methods in the include target.

Converting to/from JSON (collapse)

Instance Method Details

- (Tree::TreeNode) json_create(json_hash)

Helper method to create a Tree::TreeNode instance from the JSON hash representation. Note that this method should NOT be called directly. Instead, to convert the JSON hash back to a tree, do:

tree = JSON.parse(the_json_hash)

This operation requires the JSON gem to be available, or else the operation fails with a warning message.

Parameters:

  • json_hash (Hash)

    The JSON hash to convert from.

Returns:

See Also:

Author:

Since:

  • 0.7.0



115
116
117
118
119
120
121
122
123
124
125
# File 'lib/tree/utils/json_converter.rb', line 115

def json_create(json_hash)

  node = new(json_hash["name"], json_hash["content"])

  json_hash["children"].each do |child|
    node << child
  end if json_hash["children"]

  return node

end