lib/real_zip.rb in real_zip-0.2.0 vs lib/real_zip.rb in real_zip-1.0.0
- old
+ new
@@ -54,19 +54,51 @@
# first_dir = nil
dirs(struct).each do |dir|
first_dir = dir
z.dir.mkdir(dir) unless z.file.exist? dir
end
- op1 = struct
- arr = op1.values.first
+
+ hash = struct
+ puts "hash => #{hash}"
+ hash.each do |dir,file_arr|
+ puts "directory ======> #{dir}"
+ puts "file_array ======> #{file_arr.to_s}"
+
+ new_files = files({dir => file_arr})
+ puts "new files ======> #{new_files.to_s}"
+ new_files.each_with_index do |file, index|
+ puts "file ======> #{file} index => #{index}"
+ orignal_file_path = file_arr[index]
+ puts "orignal_file_path ==========> #{orignal_file_path}"
+ string = File.open(orignal_file_path, 'r'){ |f| f.read }
+ file_name = file.split('/').last
+ new_file_name = ( files( {dir => [ "#{file_name}" ] } ) ).first
+ puts "file_name ========> #{file_name}"
+ z.file.open(new_file_name, "w") { |f| f.write string }
+ end
+ end
+
+
+ # op1 = struct
+ # # arr = op1.values.first
+ # # op2 = files(op1)
+ # # res = op1.to_s + " ==== " + op2.to_s
# op2 = files(op1)
- # res = op1.to_s + " ==== " + op2.to_s
- files(op1).each_with_index do |file,index|
- file_path = arr[index]
- # FileUtils.cp("/home/raw/Code/prasad/zip.rake", file)
- string = File.open(file_path, 'r'){ |f| f.read }
- z.file.open(file, "w") { |f| f.write string }
- end
+ # puts "files(op1) ========> #{op2}"
+ # files(op1).each_with_index do |file,index|
+ # puts "file => #{file}"
+ # key = ( file.split("//").first ).to_sym
+ # puts "Key ====> #{key} "
+ # arr = op1[key]
+ # puts "arr of file => #{arr.to_s}"
+ # file_path = arr[0]
+ # puts "file_path ======> #{file_path}"
+ # # file_path = arr[index]
+ # # FileUtils.cp("/home/raw/Code/prasad/zip.rake", file)
+ # string = File.open(file_path, 'r'){ |f| f.read }
+ # puts "===== #{op1.to_s}"
+ # z.file.open(file, "w") { |f| f.write string }
+ # end
end
end
def struct given=file_structure
given.is_a?(String) ? YAML.load(given) : given
\ No newline at end of file