Class: TreeNode
- Inherits:
-
Object
- Object
- TreeNode
- Defined in:
- ext/ae-file-history/ae-file-history.rb
Instance Attribute Summary collapse
-
#helptext ⇒ Object
Returns the value of attribute helptext.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#label ⇒ Object
Returns the value of attribute label.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
-
#rif ⇒ Object
Returns the value of attribute rif.
-
#sons ⇒ Object
readonly
Returns the value of attribute sons.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #dir(_path) ⇒ Object
-
#initialize(parent = nil, kind = 'KClass') {|_self| ... } ⇒ TreeNode
constructor
A new instance of TreeNode.
Constructor Details
#initialize(parent = nil, kind = 'KClass') {|_self| ... } ⇒ TreeNode
Returns a new instance of TreeNode.
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
#helptext ⇒ Object
Returns the value of attribute helptext.
16 17 18 |
# File 'ext/ae-file-history/ae-file-history.rb', line 16 def helptext @helptext end |
#kind ⇒ Object (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 |
#label ⇒ Object
Returns the value of attribute label.
16 17 18 |
# File 'ext/ae-file-history/ae-file-history.rb', line 16 def label @label end |
#parent ⇒ Object (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 |
#rif ⇒ Object
Returns the value of attribute rif.
16 17 18 |
# File 'ext/ae-file-history/ae-file-history.rb', line 16 def rif @rif end |
#sons ⇒ Object (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 |