Class: Folder

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Folder

Returns a new instance of Folder.



3
4
5
6
7
# File 'lib/prestruct/folder.rb', line 3

def initialize(name)
  @path = name
  @files = []
  @folders = {}
end

Instance Attribute Details

#filesObject

Returns the value of attribute files.



2
3
4
# File 'lib/prestruct/folder.rb', line 2

def files
  @files
end

#foldersObject

Returns the value of attribute folders.



2
3
4
# File 'lib/prestruct/folder.rb', line 2

def folders
  @folders
end

Instance Method Details

#add_files(*files) ⇒ Object



9
10
11
12
13
# File 'lib/prestruct/folder.rb', line 9

def add_files(*files)
  files.each do |file|
    @files << {path: "#{@path}/#{file[0]}", contents: file[1]}
  end
end

#add_folder(name) ⇒ Object



15
16
17
18
# File 'lib/prestruct/folder.rb', line 15

def add_folder(name)
  # consider making splat argument and being able to add multiple folders
  @folders[name.to_s] = Folder.new("#{@path}/#{name}")
end

#createObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/prestruct/folder.rb', line 20

def create
  # create own directory
  Dir.mkdir(@path)

  # create all files within directory
  @files.each { |file| rw_file(file[:path], file[:contents]) } unless @files.empty?

  # for each folder in @folders, run create method
  @folders.values.each { |folder| folder.create } unless @folders.empty?
end

#to_sObject



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

def to_s
  @path
end