-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreorganize_repo.rb
34 lines (33 loc) · 1.3 KB
/
reorganize_repo.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require 'fileutils'
# moves new solutions into difficulty folders
# and deletes auto generated NOTES.md files
Dir.each_child(__dir__) do |child_dir_name|
if child_dir_name.match /^\d+/
cur_dir = "#{__dir__}/#{child_dir_name}"
difficulty = '' # serves as a flag in outer scope
has_notes = false
Dir.each_child(cur_dir) do |filename|
if filename == 'README.md'
first_line = File.open("#{cur_dir}/#{filename}", &:readline)
difficulty_first_letter = first_line[first_line.index('h3') + 3]
difficulty = case difficulty_first_letter
when 'E' then 'easy'
when 'M' then 'medium'
when 'H' then 'hard'
else ''
end
end
has_notes = true if filename == 'NOTES.md'
end
if difficulty != ""
puts "Moving #{child_dir_name} to #{difficulty} folder..."
FileUtils.mv cur_dir, "#{__dir__}/#{difficulty}/#{child_dir_name}"
else
puts "Cannot determine problem difficulty for #{child_dir_name}"
end
if has_notes
puts "Deleting empty NOTES.md file for #{child_dir_name}"
FileUtils.rm_f ["#{cur_dir}/NOTES.md"]
end
end
end