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



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

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.



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

def helptext
  @helptext
end

#kindObject (readonly)

Returns the value of attribute kind.



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

def kind
  @kind
end

#labelObject

Returns the value of attribute label.



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

def label
  @label
end

#parentObject (readonly)

Returns the value of attribute parent.



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

def parent
  @parent
end

#rifObject

Returns the value of attribute rif.



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

def rif
  @rif
end

#rif_endObject

Returns the value of attribute rif_end.



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

def rif_end
  @rif_end
end

#sonsObject (readonly)

Returns the value of attribute sons.



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

def sons
  @sons
end

Instance Method Details

#<=>(other) ⇒ Object



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

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

#dir(_path) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'ext/ae-file-history/ae-file-history.rb', line 33

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 == '/' || _path == '\\'
       # ok -- we have the root
    elsif _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