Class: PathNode

Inherits:
Object
  • Object
show all
Defined in:
app/models/path_node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePathNode

Returns a new instance of PathNode.



3
4
5
6
7
8
9
# File 'app/models/path_node.rb', line 3

def initialize
  @path=""
  @entries=Array.new
  @parent=nil
  @children=Hash.new
  @count=0
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



2
3
4
# File 'app/models/path_node.rb', line 2

def children
  @children
end

#countObject

Returns the value of attribute count.



2
3
4
# File 'app/models/path_node.rb', line 2

def count
  @count
end

#entriesObject

Returns the value of attribute entries.



2
3
4
# File 'app/models/path_node.rb', line 2

def entries
  @entries
end

#parentObject

Returns the value of attribute parent.



2
3
4
# File 'app/models/path_node.rb', line 2

def parent
  @parent
end

#pathObject

Returns the value of attribute path.



2
3
4
# File 'app/models/path_node.rb', line 2

def path
  @path
end

Instance Method Details

#addpath(n) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'app/models/path_node.rb', line 39

def addpath(n)
  if @path=="/" then
   strary=n.path.split(/\//)
   strary.delete_at(0)
   #entry=strary[strary.size-1]
   strary.pop
   node=addpath_r(strary)
   node.entries.push(n)
  end
end

#addpath_r(strary) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/models/path_node.rb', line 11

def addpath_r(strary)
  @count=@count+1
  if strary.size==0 then
    return self
  else
    cur = strary.shift()
    if @children.key?(cur) then
	@children[cur].addpath_r(strary)
    else
	newnode=PathNode.new
      newnode.path=cur
      @children[cur]=newnode
	newnode.addpath_r(strary)
    end
  end
end

#find_child(str) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'app/models/path_node.rb', line 28

def find_child(str)
  if @children then
    @children.each{|c|
      if c.path==str then
        return c
      end
    }
  end
  return
end