class DuplicatedFilenameChecker::Check
Public Class Methods
new(*check_direcotry_roots)
click to toggle source
# File lib/duplicated_filename_checker/check.rb, line 2 def initialize(*check_direcotry_roots) argument_size_validation!(check_direcotry_roots) check_directory_exists_validation!(check_direcotry_roots) @check_target_paths = check_target_paths_by(check_direcotry_roots) end
Public Instance Methods
execute()
click to toggle source
# File lib/duplicated_filename_checker/check.rb, line 9 def execute duplicate_paths.group_by(&:basename) end
Private Instance Methods
argument_size_validation!(check_direcotry_roots)
click to toggle source
# File lib/duplicated_filename_checker/check.rb, line 50 def argument_size_validation!(check_direcotry_roots) unless check_direcotry_roots.size > 0 raise ArgumentError.new('Specify the argument. Argument is survey target root paths.') end end
basename_with_count()
click to toggle source
@return [Hash] basename with same basename count. @example { “basename_a.png” => 1, “basename_b.png” => 3, “basename_c.png” => 1 }
# File lib/duplicated_filename_checker/check.rb, line 28 def basename_with_count unless @basename_count.nil? # memorize return @basename_count end @basename_count = Hash.new(0) @check_target_paths.each do |file| @basename_count[file.basename] += 1 end @basename_count end
check_directory_exists_validation!(check_direcotry_roots)
click to toggle source
# File lib/duplicated_filename_checker/check.rb, line 56 def check_directory_exists_validation!(check_direcotry_roots) check_direcotry_roots.each do |dir| unless File.exists?(dir) raise ArgumentError.new("No such directory: #{dir}") end end end
check_target_paths_by(root_paths)
click to toggle source
# File lib/duplicated_filename_checker/check.rb, line 42 def check_target_paths_by(root_paths) # get paths in subdirectory paths = root_paths.map{|root| Dir.glob("#{root}/**/*.*") }.flatten # exchange to FileProfile paths.map{|path| DuplicatedFilenameChecker::FileProfile.new(path) } end
duplicate_paths()
click to toggle source
select duplicate paths from check target paths
# File lib/duplicated_filename_checker/check.rb, line 16 def duplicate_paths @check_target_paths.select do |file| is_duplicate?(file.basename) end end
is_duplicate?(basename)
click to toggle source
# File lib/duplicated_filename_checker/check.rb, line 22 def is_duplicate?(basename) basename_with_count[basename] > 1 end