Class: TreeNode

Inherits:
Object
  • Object
show all
Defined in:
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



18
19
20
21
22
23
24
25
26
27
# File 'ext/ae-file-history/ae-file-history.rb', line 18

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

Instance Attribute Details

#helptextObject

Returns the value of attribute helptext.



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

def helptext
  @helptext
end

#kindObject (readonly)

Returns the value of attribute kind.



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

def kind
  @kind
end

#labelObject

Returns the value of attribute label.



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

def label
  @label
end

#parentObject (readonly)

Returns the value of attribute parent.



14
15
16
# File 'ext/ae-file-history/ae-file-history.rb', line 14

def parent
  @parent
end

#rifObject

Returns the value of attribute rif.



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

def rif
  @rif
end

#sonsObject (readonly)

Returns the value of attribute sons.



13
14
15
# File 'ext/ae-file-history/ae-file-history.rb', line 13

def sons
  @sons
end

Instance Method Details

#<=>(other) ⇒ Object



29
30
31
# File 'ext/ae-file-history/ae-file-history.rb', line 29

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