Class: BigResources::FileScanUtil

Inherits:
Object
  • Object
show all
Defined in:
lib/big_resources/util/image/file_scan_util.rb

Class Method Summary collapse

Class Method Details

.detect_file_by_name(dic, file_type, last_path, result_dic) ⇒ Object

分析同名文件



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/big_resources/util/image/file_scan_util.rb', line 12

def self.detect_file_by_name(dic, file_type, last_path, result_dic)
  current_path = get_current_path(last_path,dic["name"])
  current_path = last_path if last_path == dic["name"]
  if TreeHierarchyType.type(dic["type"]) == DIRECTORY
    dic["contents"].collect do | contents_dic |
      detect_file_by_name(contents_dic, file_type, current_path, result_dic)
    end
  elsif TreeHierarchyType.type(dic["type"]) == FILE
    if dic["contents"] == nil
      if  dic["name"] != nil && dic["name"].include?(file_type)
        if result_dic[dic["name"]] == nil
          result_dic[dic["name"]] = {:count => 1, :path => [current_path]}
        else
          result_dic[dic["name"]][:count] += 1
          result_dic[dic["name"]][:path] << current_path
        end
      end

    else
      dic["contents"].collect do | contents_dic |
        detect_file_by_name(contents_dic, file_type, current_path, result_dic)
      end
    end
  end
end

.detect_file_by_size(dic, file_type, last_path, result_dic) ⇒ Object

分析图片文件大小



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/big_resources/util/image/file_scan_util.rb', line 39

def self.detect_file_by_size(dic, file_type, last_path, result_dic)
  current_path = get_current_path(last_path,dic["name"])
  current_path = last_path if last_path == dic["name"]
  if TreeHierarchyType.type(dic["type"]) == DIRECTORY
    dic["contents"].collect do | contents_dic |
      detect_file_by_size(contents_dic, file_type, current_path, result_dic)
    end
  elsif TreeHierarchyType.type(dic["type"]) == FILE
    if dic["contents"] == nil
      if  dic["name"] != nil && dic["name"].include?(file_type)
        file_size = File.size(current_path)
        if file_size && result_dic["#{file_size} kb"] == nil
          result_dic["#{file_size} kb"] = {:count => 1, :path => [current_path]}
        else
          result_dic["#{file_size} kb"][:count] += 1
          result_dic["#{file_size} kb"][:path] << current_path
        end
      end

    else
      dic["contents"].collect do | contents_dic |
        detect_file_by_size(contents_dic, file_type, current_path, result_dic)
      end
    end
  end
end

.file_with_type(name, type) ⇒ Object



7
8
9
# File 'lib/big_resources/util/image/file_scan_util.rb', line 7

def self.file_with_type(name, type)
  PictureFileType.is_type(name, type)
end

.get_current_path(last_path, file_name) ⇒ Object



110
111
112
# File 'lib/big_resources/util/image/file_scan_util.rb', line 110

def self.get_current_path(last_path,file_name)
  "#{last_path}/#{file_name}"
end

.get_duplicate_name_file(dic) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/big_resources/util/image/file_scan_util.rb', line 66

def self.get_duplicate_name_file(dic)
  duplicate = []
  dic.keys.select do | file_name_key |
    if dic[file_name_key][:count] > 1
      duplicate << {"file_name" => file_name_key,
                        "count" => dic[file_name_key][:count],
                        "path" => dic[file_name_key][:path]}
    end
  end
  duplicate
end

.get_same_file(dic) ⇒ Object

根据字节大小相等 分出相同数据



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/big_resources/util/image/file_scan_util.rb', line 79

def self.get_same_file(dic)
  duplicate = []
  dic.keys.select do | file_size |
    patterns = []
    if dic[file_size][:count] > 1
      dic[file_size][:path].each do | file_path |
        if patterns.count == 0
          patterns << [file_path]
          next
        end

        is_same = false
        patterns.each do | a_pattern |
            is_same = DifferAnalyzeUtil.image_diff_analyze(file_path,a_pattern.first)
            if is_same
              a_pattern << file_path
              break
            end
        end
        patterns << [file_path] unless is_same
      end
    end
    duplicate << {:file_size => file_size,
                  :count => dic[file_size][:count],
                  :path => dic[file_size][:path],
                  :pattern => patterns
                 }
  end
  duplicate
end