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

#json_create(json_hash) ⇒ Tree::TreeNode

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



119
120
121
122
123
124
125
126
127
128
129
# File 'lib/tree/utils/json_converter.rb', line 119

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']

  node

end