Class: Ld::Tree
- Inherits:
-
Object
- Object
- Ld::Tree
- Defined in:
- lib/ld.rb,
lib/ld/tree.rb
Instance Attribute Summary collapse
-
#depth ⇒ Object
Returns the value of attribute depth.
-
#id ⇒ Object
Returns the value of attribute id.
-
#nodes ⇒ Object
Returns the value of attribute nodes.
-
#root_name ⇒ Object
Returns the value of attribute root_name.
-
#root_path ⇒ Object
Returns the value of attribute root_path.
Instance Method Summary collapse
-
#initialize(root_path) ⇒ Tree
constructor
A new instance of Tree.
- #print_tree ⇒ Object
- #read_tree(path = @root_path) ⇒ Object
Constructor Details
#initialize(root_path) ⇒ Tree
Returns a new instance of Tree.
4 5 6 7 8 9 10 11 |
# File 'lib/ld/tree.rb', line 4 def initialize root_path @root_path = root_path @root_name = File.basename root_path @nodes = Ld::Nodes.new @numbers = 0 @depth = 0 @id = 0 end |
Instance Attribute Details
#depth ⇒ Object
Returns the value of attribute depth.
2 3 4 |
# File 'lib/ld/tree.rb', line 2 def depth @depth end |
#id ⇒ Object
Returns the value of attribute id.
2 3 4 |
# File 'lib/ld/tree.rb', line 2 def id @id end |
#nodes ⇒ Object
Returns the value of attribute nodes.
2 3 4 |
# File 'lib/ld/tree.rb', line 2 def nodes @nodes end |
#root_name ⇒ Object
Returns the value of attribute root_name.
2 3 4 |
# File 'lib/ld/tree.rb', line 2 def root_name @root_name end |
#root_path ⇒ Object
Returns the value of attribute root_path.
2 3 4 |
# File 'lib/ld/tree.rb', line 2 def root_path @root_path end |
Instance Method Details
#print_tree ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/ld/tree.rb', line 26 def print_tree puts "#{@root_name}:" @nodes.sort_by_depth.each do |node| if node.type == 1 print_tree else puts "\t"*node.id + "#{node.type}:#{node.name}" end end end |
#read_tree(path = @root_path) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ld/tree.rb', line 13 def read_tree path = @root_path @depth+=1 Dir.foreach(path)do |p| if !p.match(/^\./) node = Ld::Node.new(@id+=1, @depth, "#{path}/#{p}") @nodes << node if node.type == 1 read_tree node.path end end end end |