Class: HappyDayPlugin::FindImage

Inherits:
Object
  • Object
show all
Defined in:
lib/happy_day_plugin.rb

Overview

class CH def initialize(p) @v = p end def hello puts “hello” + @v end end

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ FindImage

Returns a new instance of FindImage.



33
34
35
36
37
# File 'lib/happy_day_plugin.rb', line 33

def initialize(dir)
  @imgs = Array.new
  @mFiles = Array.new
  @dir = dir
end

Instance Method Details

#checkImageUsingObject

检查图片是否有被使用



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/happy_day_plugin.rb', line 79

def checkImageUsing
  @imgs.each do |img|
    _isUsed = false
    @mFiles.each do |file|
      # 在file中检查 img
      content = File.read(file)
      # puts content
      is2 = content =~ /#{File.basename(img, '@2x.png')}(.*)/
      is3 = content =~ /#{File.basename(img, '@3x.png')}(.*)/
      if (is2 || is3)
        _isUsed = true
      end
    end

    unless _isUsed
      outFile = File.new("unused.txt", "a+")
      if outFile
        outFile.syswrite(img)
        outFile.syswrite("\n")
      end
      puts img
    end
  end
end

#findObject



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/happy_day_plugin.rb', line 104

def find
  puts "|--开始"

  findImageWithPathDir(@dir)
  findMwithPathDir(@dir)
  puts "|--没有使用\n"
  checkImageUsing

  # @imgs.each do |img|
  #  puts img
  # end

  # @mFiles.each do |file|
  #  puts file
  # end

  puts "|--结束"
end

#findImageWithPathDir(pathDir) ⇒ Object

获得文件夹内的所有图片



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/happy_day_plugin.rb', line 40

def findImageWithPathDir(pathDir)

  Dir.foreach(pathDir) do |file|

    if file != '.' && file != '..' && !file.eql?('Pods')
      if File.directory? ("#{pathDir}/#{file}")

        findImageWithPathDir("#{pathDir}/#{file}")
      else 
        isPng = file.end_with? ".png"
        isJpg = file.end_with? ".jpg"
        if isPng || isJpg
          @imgs.push("#{pathDir}/#{file}")
        end
      end
    end
  end
end

#findMwithPathDir(pathDir) ⇒ Object

获得文件夹内所有.m文件



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/happy_day_plugin.rb', line 60

def findMwithPathDir(pathDir)
  Dir.foreach(pathDir) do |file|

    if file != '.' && file != '..'
      if File.directory? ("#{pathDir}/#{file}")

        findMwithPathDir("#{pathDir}/#{file}")
      else 
        isM = file.end_with? ".m"
        isJson = file.end_with? ".json"
        if isM || isJson
          @mFiles.push("#{pathDir}/#{file}")
        end
      end
    end
  end
end