From d58ddb17162816be594fb788b710a9016916deaf Mon Sep 17 00:00:00 2001
From: Nathan Upchurch <nathan@upchur.ch>
Date: Tue, 5 Sep 2023 18:22:11 -0400
Subject: [PATCH] Add directomatic.rb

---
 directomatic.rb | 189 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 189 insertions(+)
 create mode 100644 directomatic.rb

diff --git a/directomatic.rb b/directomatic.rb
new file mode 100644
index 0000000..aaed497
--- /dev/null
+++ b/directomatic.rb
@@ -0,0 +1,189 @@
+class DirectoryMaker
+	attr_accessor :directory_queue
+
+	def initialize(directory_queue)
+		@directory_queue = directory_queue
+	end
+
+	def add_directory
+		puts "\nEnter directory name: "
+		name = gets.chomp
+		if name.include? "/"
+			system "clear"
+			print_header
+			view_directory_queue
+			puts "\n#{name} is invalid.\n\n"
+			add_directory
+		elsif directory_queue.include?(name)
+			system "clear"
+			puts "\n#{name} already exists in directory queue.\n\n"
+			add_directory
+		else
+			directory_queue.push name
+			system "clear"
+			print_header
+			view_directory_queue
+			puts "\nAdded #{name} to directory queue. Add another? (y/n)\n"
+
+			chosen_action = gets.chomp
+			puts "\n"
+
+			case chosen_action
+			when "y"
+				system "clear"
+				print_header
+				view_directory_queue
+				add_directory
+			when "n"
+				system "clear"
+				start
+			else
+				system "clear"
+				print_header
+				view_directory_queue
+				puts "\n#{chosen_action} is an invalid selection.\n\n"
+				choose_action
+			end
+		end
+		system "clear"
+		choose_action
+	end
+
+	def view_directory_queue
+		if directory_queue.empty?
+			puts "---------------Directory Queue (Empty)----------------\n\n"
+			puts "         (Add some directories to the queue!)         \n\n"
+			puts "-------------------------------------------------------\n"
+		else
+			puts "--------------------Directory Queue--------------------\n\n"
+			puts directory_queue
+			puts "\n-------------------------------------------------------\n"
+		end
+	end
+
+	def remove_directory
+		puts "\nPlease enter the name of the directory you'd like to remove from the queue:\n"
+		name = gets.chomp
+		if directory_queue.include?(name)
+			directory_queue.delete(name)
+			system "clear"
+			print_header
+			view_directory_queue
+			puts "\n#{name} has been deleted from the directory queue.\n\n"
+			choose_action
+		else
+			system "clear"
+			print_header
+			view_directory_queue
+			puts "\n#{name} does not exist.\n\n"
+			choose_action
+		end
+	end
+
+	def edit_directory
+		puts "\nPlease enter the name of the directory you'd like to edit:\n"
+		puts "\n"
+		name = gets.chomp
+		puts "\n"
+		if directory_queue.include?(name)
+			system "clear"
+			print_header
+			view_directory_queue
+			puts "\nPlease enter new name for #{name}:\n"
+			new_name = gets.chomp
+			directory_queue[directory_queue.find_index(name)] = new_name
+			system "clear"
+			print_header
+			view_directory_queue
+			puts "\n#{name} has been changed to #{new_name}.\n\n"
+			choose_action
+		else
+			system "clear"
+			print_header
+			view_directory_queue
+			puts "\n#{name} does not exist.\n\n"
+			choose_action
+		end
+	end
+
+	def create_directories
+		puts "\nWhere would you like to put your new directories?\n"
+		location = gets.chomp
+		if Dir.exists?(location)
+			Dir.chdir(location)
+			system "clear"
+			print_header
+			puts "\nCreating directories..."
+			puts "-------------------------------------------------------\n\n"
+			for directory in directory_queue
+				if Dir.exists?(directory)
+					puts "- #{directory} exists, skipping...\n"
+				else
+					puts "- Creating #{directory}...\n"
+					Dir.mkdir(directory)
+				end
+			end
+			puts "\n-------------------------------------------------------\n\n"
+			puts "\nDone! Thank you for using Directomatic!\n\n"
+			exit 0
+		else
+			system "clear"
+			print_header
+			view_directory_queue
+			puts "\n#{location} does not exist. Please try again:\n\n"
+			choose_action
+		end
+	end
+
+	def choose_action
+		puts "\n1) Add   2) Edit   3) Remove   4) Generate Directories\n\n"
+		chosen_action = gets.chomp
+
+		case chosen_action
+		when "1"
+			system "clear"
+			print_header
+			view_directory_queue
+			add_directory
+		when "2"
+			system "clear"
+			print_header
+			view_directory_queue
+			edit_directory
+		when "3"
+			system "clear"
+			print_header
+			view_directory_queue
+			remove_directory
+		when "4"
+			system "clear"
+			print_header
+			view_directory_queue
+			create_directories
+		else
+			system "clear"
+			print_header
+			view_directory_queue
+			puts "\n#{chosen_action} is an invalid selection. Please try again:\n"
+			choose_action
+		end
+	end
+
+	def print_header
+		puts "|=====================================================|"
+		puts "|                     DIRECTOMATIC                    |"
+		puts "|      Generate multiple directories in a flash!      |"
+		puts "|=====================================================|\n\n"
+	end
+
+	def start
+		print_header
+		view_directory_queue
+		choose_action
+	end
+end
+
+directories = DirectoryMaker.new([])
+system "clear"
+directories.start
+