Class: PhotoHelper::Move

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/photo-helper/move.rb

Instance Method Summary collapse

Instance Method Details

#jpeg(folder = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/photo-helper/move.rb', line 17

def jpeg(folder = nil)
  folder ||= options[:folder]
  puts folder

  search_path = File.expand_path(folder)

  files =
    if options[:recursive]
      Dir["#{search_path}/**/*.{#{JPEG_EXTENSIONS.join(",")}}"]
    else
      Dir["#{search_path}/*.{#{JPEG_EXTENSIONS.join(",")}}"]
    end

  files.each do |file|
    next if FileHelper.ingore_file?(file)
    relative_path = Pathname.new(file).relative_path_from(Pathname.new(PHOTOS_ROOT)).to_s
    new_path = File.join(JPEG_ROOT, relative_path)
    path_dir = File.dirname(new_path)

    FileUtils.mkdir_p path_dir unless File.exists? path_dir

    FileUtils.mv file, new_path 

  end
end