Class: Folder
- Inherits:
-
Object
- Object
- Folder
- Defined in:
- lib/prestruct/folder.rb
Instance Attribute Summary collapse
-
#files ⇒ Object
Returns the value of attribute files.
-
#folders ⇒ Object
Returns the value of attribute folders.
Instance Method Summary collapse
- #add_files(*files) ⇒ Object
- #add_folder(name) ⇒ Object
- #create ⇒ Object
-
#initialize(name) ⇒ Folder
constructor
A new instance of Folder.
- #to_s ⇒ Object
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
#files ⇒ Object
Returns the value of attribute files.
2 3 4 |
# File 'lib/prestruct/folder.rb', line 2 def files @files end |
#folders ⇒ Object
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 |
#create ⇒ Object
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_s ⇒ Object
31 32 33 |
# File 'lib/prestruct/folder.rb', line 31 def to_s @path end |