-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: Tree.create_from_hash() #13
Comments
Sure Mark, It is a good idea. It needs to be a class method in a utility mixin (similar to the JSON implementation). It should probably be named as from_hash() Can you fork the master on Github, and then send me the merge request with your changes? Best Regards,Anupam On Dec 1, 2012, at 6:41 PM, Mark Thomas [email protected] wrote:
|
In my fork I have implemented a So my latest thinking is to keep only the instance method. To create a new tree, one would have to create a root TreeNode first, then import the hash, e.g. What do you think? |
Mark, This sounds good. Can you send the pull request? You might want to merge in my latest changes to the master first. |
Mark, I am about to make a Rubytree release this weekend. Would it be possible for you to send me a pull request for the hash export/import code that you have created? |
I'll review it today and let you know if it's ready.
|
Unfortunately, there is still a small amount of work for me to do. I was On Fri, Feb 22, 2013 at 6:07 AM, Mark Thomas [email protected]:
|
Feature request completed. Thanks to @jhamon for providing the feature code and patch. |
So does this feature only work if all the final values are nil or a hash then? What about a real-world hash with data and content in it? For example Tree::TreeNode.from_hash( {"en"=>
{"courses"=>"Courses",
"layouts"=>{"navigation"=>{"desktop"=>{"browse_courses"=>"Browse Courses", "this_one"=>false}}},
"unrelated"=>{"dont"=>{"include"=>"this, please"}}}})
#=> ArgumentError: Invalid child. Must be nil or hash.
#=> from /app/RubyTree/lib/tree/utils/hash_converter.rb:106:in `from_hash' |
I think RubyTree should have convenience methods to convert built-in hierarchical structures to trees. I propose
Tree.create_from_hash(hash)
as a class method. After all, you have JSON input/output, why not built-in data structures. I'd like for it to work with arbitrary nested hashes.A few questions:
Is it OK as a class method? I think it makes sense.
Naming: do you prefer
Tree.create_from_hash()
orTree.from_hash()
?Would you want it directly in the
Tree
class or split out into utility class like JSON is?The text was updated successfully, but these errors were encountered: