Class: TreeNode

Inherits:
Object
  • Object
show all
Defined in:
ext/ae-editor/ae-editor.rb,
ext/ae-file-history/ae-file-history.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent = nil, kind = 'KClass') {|_self| ... } ⇒ TreeNode

Returns a new instance of TreeNode.

Yields:

  • (_self)

Yield Parameters:

  • _self (TreeNode)

    the object that the method was called on



20
21
22
23
24
25
26
27
28
# File 'ext/ae-editor/ae-editor.rb', line 20

def initialize(parent=nil, kind='KClass')
  @sons = Array.new
  @parent = parent
  @kind = kind
  if @parent !=nil
    @parent.sons << self
  end
  yield(self) if block_given?
end

Instance Attribute Details

#helptextObject

Returns the value of attribute helptext.



18
19
20
# File 'ext/ae-editor/ae-editor.rb', line 18

def helptext
  @helptext
end

#kindObject (readonly)

Returns the value of attribute kind.



17
18
19
# File 'ext/ae-editor/ae-editor.rb', line 17

def kind
  @kind
end

#labelObject

Returns the value of attribute label.



18
19
20
# File 'ext/ae-editor/ae-editor.rb', line 18

def label
  @label
end

#parentObject (readonly)

Returns the value of attribute parent.



16
17
18
# File 'ext/ae-editor/ae-editor.rb', line 16

def parent
  @parent
end

#rifObject

Returns the value of attribute rif.



18
19
20
# File 'ext/ae-editor/ae-editor.rb', line 18

def rif
  @rif
end

#rif_endObject

Returns the value of attribute rif_end.



18
19
20
# File 'ext/ae-editor/ae-editor.rb', line 18

def rif_end
  @rif_end
end

#sonsObject (readonly)

Returns the value of attribute sons.



15
16
17
# File 'ext/ae-editor/ae-editor.rb', line 15

def sons
  @sons
end

Instance Method Details

#<=>(other) ⇒ Object



30
31
32
# File 'ext/ae-editor/ae-editor.rb', line 30

def <=> (other)
  self.label.strip <=> other.label.strip
end

#dir(_path) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'ext/ae-file-history/ae-file-history.rb', line 63

def dir(_path)
  node = nil
  parent = self
  sons.each{|_tree|
      ["\\","/"].include?(_path[0,1])?_index = 1:_index=0
     if _path[_index.._tree.label.length-1+_index] == _tree.label 
			 res = _path[_tree.label.length+_index.._path.length-1]
			 if ["\\","/"].include?(res[0,1])
             parent = _tree
             node= _tree.dir(res)
			 end
		 end
		 break if node != nil
  }
  if node == nil
    if _path.length > 0 && (_path.include?("/")||_path.include?("\\"))
      _path.include?("/")?_sep="/":_sep="\\"
      _parent_length = _path.length - _path.split(_sep)[-1].length
      _parent_path = _path[0.._parent_length-2]
      if _parent_path != _path
        parent = parent.dir(_parent_path)
   	      _path = _path[_parent_length-1.._path.length-1]
      end
    end
    node = TreeNode.new(parent,'KDir') do |_node|
     		_node.label=_path
  		   if ["\\","/"].include?(_node.label[0,1])
  		     _node.label = _node.label[1..-1]
  		   end
  		   parent.rif == "root"?parent_rif = "":parent_rif=parent.rif
     		_node.rif= (parent_rif+_path).sub(":",'%%%')
    end
  end
  return node
end

#dir_old(_path) ⇒ Object

def path

_path = @label
if @parent != nil
  _path = @parent.path+_path
end
return _path

end



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'ext/ae-file-history/ae-file-history.rb', line 41

def dir_old(_path)
  node = nil
  parent = self
  sons.each{|_tree|
     if _path[0.._tree.label.length-1] == _tree.label 
			 res = _path[_tree.label.length.._path.length-1]
			 if ["\\","/"].include?(res[0,1])
             parent = _tree
             node= _tree.dir(res)
			 end
		 end
		 break if node != nil
  }
  if node == nil
    node = TreeNode.new(parent,'KDir') do |_node|
     		_node.label=_path
     		_node.rif= parent.path+_path
    end
  end
  return node
end