lib/vedeu/support/node.rb in vedeu-0.3.4 vs lib/vedeu/support/node.rb in vedeu-0.3.5
- old
+ new
@@ -1,61 +1,51 @@
module Vedeu
+ # A composition class.
+ #
class Node
attr_accessor :name,
:parent
attr_reader :children
+ # @return [void]
def initialize(name)
@name = name
@children = []
end
+ # @return [void]
def add_child(node)
children << node
node.parent = self
end
alias :<< :add_child
+ # @return [void]
def remove_child(node)
children.delete(node)
end
+ # @return [void]
def [](index)
children[index]
end
+ # @return [void]
def []=(index, node)
replaced_child = @children[index]
children[index] = node
replaced_child.parent = nil
node.parent = self
end
+ # @return [void]
def leaf?
children.empty?
end
end # Node
-
- class Task < Node
-
- def initialize(name, time_required = nil)
- super(name)
- @time_required = time_required
- end
- def time_required
- if leaf?
- @time_required
- else
- time = 0.0
- children.each { |child_task| time += child_task.time_required }
- time
- end
- end
-
- end # Task
end # Vedeu