itools 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/itools/find_unuse_img.rb +29 -8
- data/lib/itools/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02f5e884b390172db80c0d1591554f1c10d05bfb9a9be92871ae10f5e8fe96b0
|
4
|
+
data.tar.gz: 1b998ffb957c6c9e08c020505180d0bc33fc17875557b9ef8bf42892751c5f4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2beedb55289f268a9595f63169f8780e093f8686985f54eebb4cfde52bda731c59fcebf3a40ae4a608ff99ffab452185b01c006fce0fe6fa528524c709b0b040
|
7
|
+
data.tar.gz: 4416ad45b191e7806b5f18b09a79d690b11b4a50d58758485af810308b2a8a79ce388322a5c4df7f654b7f6d0e37ae9cee817ca4685467661ef9f4eb9fafbdc7
|
data/Gemfile.lock
CHANGED
@@ -1,23 +1,40 @@
|
|
1
1
|
require 'find'
|
2
2
|
require 'spreadsheet'
|
3
3
|
module Itools
|
4
|
+
class FindResult
|
5
|
+
attr_accessor :name , :path
|
6
|
+
def initialize(name,path)
|
7
|
+
@name = name
|
8
|
+
@path = path
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
# --------------------------------------------
|
4
13
|
class ImgFinder
|
5
|
-
|
14
|
+
#
|
15
|
+
attr_accessor :image_count, :images, :unuse_images,:find_path
|
6
16
|
attr_accessor :search_files
|
7
17
|
def initialize
|
8
18
|
@image_count = 0
|
9
|
-
@
|
19
|
+
@images = []
|
10
20
|
@search_files = []
|
11
21
|
end
|
12
22
|
# 得到所有图片名称字符
|
13
23
|
def get_img_name_strs
|
14
24
|
result_arr = []
|
15
|
-
@
|
16
|
-
item_name = Image.get_image_name(File.basename(item, ".*"))
|
25
|
+
@images.each {|item|
|
26
|
+
item_name = Image.get_image_name(File.basename(item.name, ".*"))
|
17
27
|
result_arr << item_name
|
18
28
|
}
|
19
29
|
return result_arr
|
20
30
|
end
|
31
|
+
def get_image_path(image)
|
32
|
+
@images.each {|item|
|
33
|
+
if item.name.eql?(image)
|
34
|
+
return item.path
|
35
|
+
end
|
36
|
+
}
|
37
|
+
end
|
21
38
|
# 查找
|
22
39
|
def self.find(temp_find_dir)
|
23
40
|
imgFinder = ImgFinder.new
|
@@ -29,21 +46,22 @@ module Itools
|
|
29
46
|
# p File.basename(filename)
|
30
47
|
# exit
|
31
48
|
imgFinder.image_count = imgFinder.image_count + 1
|
32
|
-
|
49
|
+
imageResult = FindResult.new(Image.get_image_name(File.basename(filename,".*")),filename)
|
50
|
+
imgFinder.images << imageResult
|
33
51
|
elsif File.extname(filename).eql?(".m")
|
34
52
|
imgFinder.search_files << filename
|
35
53
|
end
|
36
54
|
end
|
37
55
|
end
|
38
|
-
if imgFinder.
|
56
|
+
if imgFinder.images.size == 0
|
39
57
|
puts "\033[32m查找成功,未发现图片\033[0m"
|
40
58
|
return
|
41
59
|
else
|
42
|
-
puts "\033[32m查找成功,共发现图片#{imgFinder.
|
60
|
+
puts "\033[32m查找成功,共发现图片#{imgFinder.images.size}张\033[0m"
|
43
61
|
end
|
44
62
|
# 第二步:找到图片是否使用
|
45
63
|
imags = imgFinder.get_img_name_strs.uniq #要查找的图片名称数组
|
46
|
-
|
64
|
+
|
47
65
|
puts "\033[32m需要查找的图片有#{imags.size}张\033[0m"
|
48
66
|
# imgFinder.search_files #要查找的文件
|
49
67
|
imgFinder.search_files.each {|file|
|
@@ -60,8 +78,10 @@ module Itools
|
|
60
78
|
book = Spreadsheet::Workbook.new
|
61
79
|
sheet1 = book.create_worksheet
|
62
80
|
sheet1.row(0)[0] = "文件名"
|
81
|
+
sheet1.row(0)[1] = "文件路径"
|
63
82
|
imags.each_with_index {|item,idx|
|
64
83
|
sheet1.row(idx+1)[0] = item
|
84
|
+
sheet1.row(idx+1)[1] = imgFinder.get_image_path(item)
|
65
85
|
puts item
|
66
86
|
}
|
67
87
|
book.write "#{imgFinder.find_path}/search_result.xls"
|
@@ -81,6 +101,7 @@ module Itools
|
|
81
101
|
return -1
|
82
102
|
end
|
83
103
|
end
|
104
|
+
# ----------------------------
|
84
105
|
class Image
|
85
106
|
|
86
107
|
# 是否是图片格式,这里只判断了jpg、png和gif
|
data/lib/itools/version.rb
CHANGED