Class: CherryTree::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/ursa/cherry-tree/node.rb

Constant Summary collapse

DEEPNESS_SYMBOL =
'----'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, parent, deepness) ⇒ Node

Returns a new instance of Node.



7
8
9
10
11
12
# File 'lib/ursa/cherry-tree/node.rb', line 7

def initialize(data, parent, deepness)
  self.data = data
  self.parent = parent
  self.deepness = deepness
  self.children = []
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



3
4
5
# File 'lib/ursa/cherry-tree/node.rb', line 3

def children
  @children
end

#dataObject

Returns the value of attribute data.



3
4
5
# File 'lib/ursa/cherry-tree/node.rb', line 3

def data
  @data
end

#deepnessObject

Returns the value of attribute deepness.



3
4
5
# File 'lib/ursa/cherry-tree/node.rb', line 3

def deepness
  @deepness
end

#parentObject

Returns the value of attribute parent.



3
4
5
# File 'lib/ursa/cherry-tree/node.rb', line 3

def parent
  @parent
end

Instance Method Details

#to_sObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/ursa/cherry-tree/node.rb', line 14

def to_s
  str = ""
  str << "#{DEEPNESS_SYMBOL * deepness}#{DEEPNESS_SYMBOL}#{data}\n"
  if children.any?
    children.each do |child|
      str << child.to_s
    end
  end
  str
end