Class: Mundane::ZipsToFiles
- Inherits:
-
Object
- Object
- Mundane::ZipsToFiles
- Extended by:
- FileWorker, Prompter
- Defined in:
- lib/mundane/algos/zips_to_files.rb
Class Method Summary collapse
Methods included from FileWorker
count_targeted_files, get_files_in_current_folder, make_output_directory
Methods included from Prompter
construct_informative_message, prompt_user
Class Method Details
.decompress_files_and_dump_them_to_out(files) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/mundane/algos/zips_to_files.rb', line 17 def self.decompress_files_and_dump_them_to_out(files) incomplete_extractions = 0 all_files_were_archives = true # decompress each file in the list files.each do |zip| # TODO: next if zip.extension != 'zip' begin Zip::File.open(zip) do |archive| archive.each do |f| output_path = "out/#{f.name}" if File.exists? output_path # don't auto-overwrite anything... puts "#{output_path} ALREADY EXISTED, SKIPPING FILE." incomplete_extractions += 1 next end FileUtils.mkdir_p File.dirname(output_path) f.extract output_path end end rescue # skip the file if it can't be opened like a zip all_files_were_archives = false end end puts "\nOperation terminated, there were #{incomplete_extractions} incomplete extractions." if incomplete_extractions > 0 puts "Not all files were valid archives" unless all_files_were_archives end |
.execute ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/mundane/algos/zips_to_files.rb', line 6 def self.execute user_wants_to_proceed = prompt_user("Are you sure you want to unzip %count_targeted_files% zip files and dump their contents into ./out/ ?\n[Y/n]") if user_wants_to_proceed make_output_directory files = get_files_in_current_folder decompress_files_and_dump_them_to_out(files) end end |