Top Level Namespace
Defined Under Namespace
Classes: Raxus
Instance Method Summary collapse
Instance Method Details
#compress(files) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/compress.rb', line 5 def compress(files) if files.size == 1 archive = File.join("/tmp", File.basename(files[0] + ".zip")) else archive = File.join("/tmp", "download.zip") end FileUtils.rm archive, :force => true Zip::ZipFile.open(archive, 'w') do |zip| files.each do |file| if File.directory? file Dir["#{file}/**/**"].each do |f| zip.add(File.join(File.basename(file), f.sub(file + '/', '')), f) end else zip.add(File.basename(file), file) end end end archive end |