回答編集履歴
1
追記
test
CHANGED
@@ -43,3 +43,47 @@
|
|
43
43
|
```
|
44
44
|
|
45
45
|
これからなら望みのjson組み立てられそうですか?
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
追記
|
50
|
+
|
51
|
+
dir配下のfileをまとめて階層ごと。
|
52
|
+
|
53
|
+
"basename" は適宜
|
54
|
+
|
55
|
+
Dir.glob(dir+"/**/*{csv,xlsx}") の拡張子も適宜
|
56
|
+
|
57
|
+
```
|
58
|
+
|
59
|
+
def compress_dir dir
|
60
|
+
|
61
|
+
temp_file = Tempfile.new("basename")
|
62
|
+
|
63
|
+
files = Dir.glob(dir+"/**/*{csv,xlsx}")
|
64
|
+
|
65
|
+
Zip::File.open(temp_file.path, Zip::File::CREATE) do |zipfile|
|
66
|
+
|
67
|
+
files.each do |file|
|
68
|
+
|
69
|
+
filename = file.sub(/#{dir}//,"")
|
70
|
+
|
71
|
+
if Rails.env == "development"
|
72
|
+
|
73
|
+
zipfile.add(filename, file)
|
74
|
+
|
75
|
+
else
|
76
|
+
|
77
|
+
zipfile.add(filename.encode("Shift_JIS"), file)
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
temp_file.path
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
```
|