Class: WikiPromoter::TreeNode

Inherits:
Object
  • Object
show all
Defined in:
lib/wiki_promoter/migrator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, parent = nil) ⇒ TreeNode

Returns a new instance of TreeNode.



10
11
12
13
14
15
# File 'lib/wiki_promoter/migrator.rb', line 10

def initialize(name, parent = nil)
  @name = name
  @parent = parent
  @subdirs = {}
  @files = []
end

Instance Attribute Details

#filesObject (readonly)

Returns the value of attribute files.



7
8
9
# File 'lib/wiki_promoter/migrator.rb', line 7

def files
  @files
end

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/wiki_promoter/migrator.rb', line 7

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



7
8
9
# File 'lib/wiki_promoter/migrator.rb', line 7

def parent
  @parent
end

#prefixObject

Returns the value of attribute prefix.



8
9
10
# File 'lib/wiki_promoter/migrator.rb', line 8

def prefix
  @prefix
end

#subdirsObject (readonly)

Returns the value of attribute subdirs.



7
8
9
# File 'lib/wiki_promoter/migrator.rb', line 7

def subdirs
  @subdirs
end

Instance Method Details

#add_file(path_parts, full_path) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/wiki_promoter/migrator.rb', line 17

def add_file(path_parts, full_path)
  if path_parts.empty?
    raise "Empty path parts"
  elsif path_parts.size == 1
    @files << full_path
  else
    subdir_name = path_parts.first
    @subdirs[subdir_name] ||= TreeNode.new(subdir_name, self)
    @subdirs[subdir_name].add_file(path_parts[1..], full_path)
  end
end