Class: Tree

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

Overview

Tree class create array of all root directories

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = Dir.pwd) ⇒ Tree

Returns a new instance of Tree.



15
16
17
18
19
20
21
# File 'lib/tree.rb', line 15

def initialize(path = Dir.pwd)
  @root = path
  @directories = 0
  @files = 0
  @tree_data = []
  @path_array = []
end

Instance Attribute Details

#directoriesObject (readonly)

Returns the value of attribute directories.



9
10
11
# File 'lib/tree.rb', line 9

def directories
  @directories
end

#filesObject (readonly)

Returns the value of attribute files.



9
10
11
# File 'lib/tree.rb', line 9

def files
  @files
end

#path_arrayObject (readonly)

Returns the value of attribute path_array.



9
10
11
# File 'lib/tree.rb', line 9

def path_array
  @path_array
end

#rootObject (readonly)

Returns the value of attribute root.



9
10
11
# File 'lib/tree.rb', line 9

def root
  @root
end

#tree_dataObject (readonly)

Returns the value of attribute tree_data.



9
10
11
# File 'lib/tree.rb', line 9

def tree_data
  @tree_data
end

Instance Method Details

#runObject



23
24
25
26
27
28
29
# File 'lib/tree.rb', line 23

def run
  @root = Pathname.new(@root)
  @root.each_child do |dir|
    @path_array << dir
    @tree_data << dir
  end
end

#run_resultsObject



31
32
33
# File 'lib/tree.rb', line 31

def run_results
  [@path_array, @directories, @files, @tree_data, @root]
end