Class: TreeThinking::BinaryTreeFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/tree_thinking/binary_tree_factory.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tree) ⇒ BinaryTreeFactory

Returns a new instance of BinaryTreeFactory.



11
12
13
# File 'lib/tree_thinking/binary_tree_factory.rb', line 11

def initialize(tree)
  @tree = tree
end

Instance Attribute Details

#treeObject (readonly)

Returns the value of attribute tree.



5
6
7
# File 'lib/tree_thinking/binary_tree_factory.rb', line 5

def tree
  @tree
end

Class Method Details

.from_yaml(path) ⇒ Object



7
8
9
# File 'lib/tree_thinking/binary_tree_factory.rb', line 7

def self.from_yaml(path)
  new(YAML.load(File.read(path))).build!
end

Instance Method Details

#build!Object



15
16
17
18
19
# File 'lib/tree_thinking/binary_tree_factory.rb', line 15

def build!
  btree = BinaryTree.new(name: tree['class_name'])
  btree.tree = nodify(tree['tree'])
  btree
end