Class: Lina::TreeNode

Inherits:
Object
  • Object
show all
Defined in:
lib/lina/tree.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, parent = nil) ⇒ TreeNode

Returns a new instance of TreeNode.



69
70
71
72
73
74
# File 'lib/lina/tree.rb', line 69

def initialize(path, parent =nil)
  @path = path
  @children = []
  @parent = parent
  @values = []
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



68
69
70
# File 'lib/lina/tree.rb', line 68

def children
  @children
end

#parentObject (readonly)

Returns the value of attribute parent.



68
69
70
# File 'lib/lina/tree.rb', line 68

def parent
  @parent
end

#pathObject (readonly)

Returns the value of attribute path.



68
69
70
# File 'lib/lina/tree.rb', line 68

def path
  @path
end

#valuesObject (readonly)

Returns the value of attribute values.



68
69
70
# File 'lib/lina/tree.rb', line 68

def values
  @values
end

Instance Method Details

#add_child(child) ⇒ Object



93
94
95
96
# File 'lib/lina/tree.rb', line 93

def add_child(child)
  @children << child
  child
end

#add_value(value) ⇒ Object



76
77
78
# File 'lib/lina/tree.rb', line 76

def add_value(value)
  @values << value
end

#find_child(path) ⇒ Object



98
99
100
# File 'lib/lina/tree.rb', line 98

def find_child(path)
  @children.find { |child| child.path == path }
end

#real_pathObject



80
81
82
83
84
85
86
87
# File 'lib/lina/tree.rb', line 80

def real_path
  ret_path = [ @path ]
  node = self
  while(node = node.parent)
    ret_path.unshift(node.path)
  end
  ret_path.join('/')
end

#root?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/lina/tree.rb', line 89

def root?
  @parent.nil?
end