Class: Forester::TreeFactory
- Inherits:
-
Object
- Object
- Forester::TreeFactory
- Defined in:
- lib/forester/tree_factory.rb
Class Method Summary collapse
- .from_hash_with_root_key(hash, options = {}) ⇒ Object
- .from_root_hash(hash, options = {}) ⇒ Object
- .from_yaml_file(file, options = {}) ⇒ Object
Class Method Details
.from_hash_with_root_key(hash, options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/forester/tree_factory.rb', line 14 def from_hash_with_root_key(hash, = {}) = { max_level: :last, children_key: :children, root_key: :root } = .merge() dummy_root = TreeNode.new('<TEMP>') real_root = fetch_indifferently(hash, [:root_key]) max_level = [:max_level] max_level = -2 if max_level == :last tree = with_children(dummy_root, [real_root], [:children_key], max_level + 1).first_child tree.detached_subtree_copy end |
.from_root_hash(hash, options = {}) ⇒ Object
10 11 12 |
# File 'lib/forester/tree_factory.rb', line 10 def from_root_hash(hash, = {}) from_hash_with_root_key({ root: hash }, ) end |
.from_yaml_file(file, options = {}) ⇒ Object
6 7 8 |
# File 'lib/forester/tree_factory.rb', line 6 def from_yaml_file(file, = {}) from_hash_with_root_key(YAML.load_file(file), ) end |