Sha256: 909ab0155ab98192fb06541b7e2d9f3d70d3c332ce51dff5f7aed20a37c49e01
Contents?: true
Size: 989 Bytes
Versions: 5
Compression:
Stored size: 989 Bytes
Contents
module Vedeu class Node attr_accessor :name, :parent attr_reader :children def initialize(name) @name = name @children = [] end def add_child(node) children << node node.parent = self end alias :<< :add_child def remove_child(node) children.delete(node) end def [](index) children[index] end def []=(index, node) replaced_child = @children[index] children[index] = node replaced_child.parent = nil node.parent = self end 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
Version data entries
5 entries across 5 versions & 1 rubygems