Class: Wraith::FolderManager

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ FolderManager

Returns a new instance of FolderManager.



6
7
8
# File 'lib/wraith/folder.rb', line 6

def initialize(config)
  @wraith = Wraith::Wraith.new(config)
end

Instance Attribute Details

#wraithObject (readonly)

Returns the value of attribute wraith.



4
5
6
# File 'lib/wraith/folder.rb', line 4

def wraith
  @wraith
end

Instance Method Details

#clear_shots_folderObject



27
28
29
30
# File 'lib/wraith/folder.rb', line 27

def clear_shots_folder
  FileUtils.rm_rf("./#{dir}")
  FileUtils.mkdir_p("#{dir}")
end

#create_foldersObject



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/wraith/folder.rb', line 32

def create_folders
  spider_paths.each do |folder_label, path|
    unless path
      path = folder_label
      folder_label = path.gsub('/', '__')
    end

    FileUtils.mkdir_p("#{dir}/thumbnails/#{folder_label}")
    FileUtils.mkdir_p("#{dir}/#{folder_label}")
  end
  puts 'Creating Folders'
end

#dirObject



10
11
12
# File 'lib/wraith/folder.rb', line 10

def dir
  wraith.directory
end

#pathsObject



14
15
16
# File 'lib/wraith/folder.rb', line 14

def paths
  wraith.paths
end

#spider_pathsObject



18
19
20
21
22
23
24
25
# File 'lib/wraith/folder.rb', line 18

def spider_paths
  if !paths
    paths = File.read(wraith.spider_file)
    eval(paths)
  else
    wraith.paths
  end
end

#tidy_shots_folder(dirs) ⇒ Object

Tidy up the shots folder, removing uncessary files



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/wraith/folder.rb', line 47

def tidy_shots_folder(dirs)
  if wraith.mode == 'diffs_only'
    dirs.each do |a, b|
      # If we are running in "diffs_only mode, and none of the variants show a difference
      # we remove the file from the shots folder
      if b.none? { |_k, v| v[:data] > 0 }
        FileUtils.rm_rf("#{wraith.directory}/#{a}")
        dirs.delete(a)
      end
    end
  end
end