class FileCrawler::Finder::Command::Move::Fixer

Public Instance Methods

fix_path(filepath, check_array, index=0) click to toggle source
# File lib/file_crawler/finder/command/move.rb, line 65
def fix_path(filepath, check_array, index=0)
  newpath = filepath
  newpath = "#{filepath} (#{index})" if index > 0
  return fix_path(filepath, check_array, index + 1) if exist?(newpath, check_array)

  newpath
end
make_fixed_paths(filepaths) click to toggle source
# File lib/file_crawler/finder/command/move.rb, line 54
def make_fixed_paths(filepaths)
  dest = []
  filepaths.each {|filepath|
    fixed_path = fix_path(filepath[1], dest)
    filepath[1] = fixed_path
    dest << fixed_path
  }

  filepaths
end
make_mv(filepaths) click to toggle source
# File lib/file_crawler/finder/command/move.rb, line 43
def make_mv(filepaths)
  cmds = []
  mkdirs = []
  make_fixed_paths(filepaths).map {|file|
    mkdirs << "mkdir -p #{File.dirname(file[1]).inspect}"
    cmds << "mv '#{file[0]}' '#{file[1]}'"
  }

  mkdirs.uniq + cmds
end
make_new_path(sources, destination) click to toggle source
# File lib/file_crawler/finder/command/move.rb, line 30
def make_new_path(sources, destination)
  case sources
  when Hash
    return make_new_path_for_collection(sources, destination)
  when Array
    return make_new_path_for_array(sources, destination)
  when String
    return make_new_path_for_array([sources], destination)
  end

  ArgumentError
end

Private Instance Methods

exist?(filepath, check_array) click to toggle source
# File lib/file_crawler/finder/command/move.rb, line 74
def exist?(filepath, check_array)
  return true if File.exist?(filepath)

  check_array.include?(filepath)
end
make_new_path_for_array(sources, destination) click to toggle source
# File lib/file_crawler/finder/command/move.rb, line 80
def make_new_path_for_array(sources, destination)
  result = []
  sources.each {|path|
    result << [path, new_path(path, destination)]
  }

  result
end
make_new_path_for_collection(sources, destination) click to toggle source
# File lib/file_crawler/finder/command/move.rb, line 89
def make_new_path_for_collection(sources, destination)
  result = []
  sources.each {|dirname, paths|
    new_dir = destination + '/' + dirname.to_s
    paths.each {|path|
      result << [path, new_path(path, new_dir)]
    }
  }

  result
end
new_path(source, destination) click to toggle source
# File lib/file_crawler/finder/command/move.rb, line 101
def new_path(source, destination)
  destination + '/' + File.basename(source)
end