Class: Lhj::Command::DuplicateImageset

Inherits:
Lhj::Command
  • Object
show all
Defined in:
lib/lhj/command/duplicate_imageset.rb

Instance Method Summary collapse

Methods inherited from Lhj::Command

#auto_spin, #begin_title, #run, #stop

Constructor Details

#initialize(argv) ⇒ DuplicateImageset

Returns a new instance of DuplicateImageset.



9
10
11
12
# File 'lib/lhj/command/duplicate_imageset.rb', line 9

def initialize(argv)
  @current_path = argv.shift_argument || Dir.pwd
  super
end

Instance Method Details

#fetch_imagesObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/lhj/command/duplicate_imageset.rb', line 30

def fetch_images
  image_map = {}
  Dir.glob("#{@current_path}/**/Assets.xcassets/**/*.imageset").each do |f|
    image_name = File.basename(f, '.*')
    models = image_map[image_name.to_sym]
    unless models
      models = []
      image_map[image_name.to_sym] = models
    end
    models << model_name_with_path(f)
  end
  image_map
end

#handleObject



14
15
16
# File 'lib/lhj/command/duplicate_imageset.rb', line 14

def handle
  write_to_file
end

#model_name_with_path(path) ⇒ Object



44
45
46
47
48
49
# File 'lib/lhj/command/duplicate_imageset.rb', line 44

def model_name_with_path(path)
  reg = %r{Code/([^/]*)/}
  reg = %r{Pods/([^/]*)/} if path =~ /Pods/
  ma = path.match(reg)
  ma[1]
end

#write_to_fileObject



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/lhj/command/duplicate_imageset.rb', line 18

def write_to_file
  map = fetch_images
  file = File.join(@current_path, 'images.cvs')
  FileUtils.rm_rf(file) if File.exist?(file)
  CSV.open(file, 'wb:utf-8') do |csv|
    csv << ['所在模块']
    map.each do |k, v|
      csv << [v.join(', ')] if v.length > 1
    end
  end
end