module Tree::Utils::JSONConverter::ClassMethods
ClassMethods for the {JSONConverter}
module. Will become class methods in the include
target.
Public Instance Methods
json_create(json_hash)
click to toggle source
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.
@author Dirk Breuer (github.com/railsbros-dirk) @since 0.7.0
@param [Hash] json_hash The JSON hash to convert from.
@return [Tree::TreeNode] The created tree.
@see to_json @see flori.github.com/json
# 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