class FindDupeImages::Finder
Attributes
hexdigest[R]
image_data[R]
Public Class Methods
run()
click to toggle source
start the scan
@return [String]
# File lib/find_dupe_images/finder.rb, line 15 def run create_traversed_directories_array define_path define_directory traverse_directory result puts result.class end
Private Class Methods
create_hexdigest()
click to toggle source
# File lib/find_dupe_images/finder.rb, line 70 def create_hexdigest @hexdigest = Digest::MD5.hexdigest @image_data.export_pixels_to_str end
create_report(results)
click to toggle source
# File lib/find_dupe_images/finder.rb, line 87 def create_report(results) results.size > 0 ? with_duplicates(results) : without_duplicates puts "\nReport:" files_too_big not_an_image end
create_traversed_directories_array()
click to toggle source
# File lib/find_dupe_images/finder.rb, line 27 def create_traversed_directories_array @traversed_directories = [] end
define_directory()
click to toggle source
# File lib/find_dupe_images/finder.rb, line 35 def define_directory @directory = Dir.glob("#{@directory_path}**/*").reject { |fn| File.directory?(fn)} end
define_path()
click to toggle source
# File lib/find_dupe_images/finder.rb, line 31 def define_path @directory_path = FindDupeImages::Option.directory_path end
files_too_big()
click to toggle source
# File lib/find_dupe_images/finder.rb, line 105 def files_too_big if $too_big > 0 puts "\t#{$too_big} files have been ignored because they are too big!" end end
log_data(filename)
click to toggle source
# File lib/find_dupe_images/finder.rb, line 61 def log_data(filename) create_hexdigest FindDupeImages.logger.log(processed_image_data.to_json) end
not_an_image()
click to toggle source
# File lib/find_dupe_images/finder.rb, line 111 def not_an_image if $not_an_image > 0 puts "\t#{$not_an_image} files have been ignored because they are not recognized as an image!" end end
processed_image_data()
click to toggle source
# File lib/find_dupe_images/finder.rb, line 74 def processed_image_data {image_data: @image_data.inspect, hexdigest: @hexdigest} end
read_image_data(filename)
click to toggle source
# File lib/find_dupe_images/finder.rb, line 66 def read_image_data(filename) @image_data = @image.image end
result()
click to toggle source
# File lib/find_dupe_images/finder.rb, line 82 def result results = FindDupeImages::Serializer.new.deserialize create_report(results) end
serialize_data()
click to toggle source
# File lib/find_dupe_images/finder.rb, line 78 def serialize_data FindDupeImages::Serializer.new(FindDupeImages::ProcessedData.new({file_name: @image_data.filename, hexdigest: @hexdigest})).serialize end
traverse_directory()
click to toggle source
# File lib/find_dupe_images/finder.rb, line 39 def traverse_directory FindDupeImages::Serializer.new.remove_marshal_file puts "\nStarting to process #{@directory.size} files in the directory ...\n\n" @directory.each do |filename| @image = FindDupeImages::Image.new(filename) if @image.is_image? read_image_data(filename) $count += 1 log_data(filename) serialize_data end trap("SIGINT") do puts 'Interrupted! Closing.' exit(0) end end end
with_duplicates(results)
click to toggle source
# File lib/find_dupe_images/finder.rb, line 94 def with_duplicates(results) puts "\n\nThe following files have been detected as duplicates:\n\n" results.each_pair do |hexdigest, file| puts file end end
without_duplicates()
click to toggle source
# File lib/find_dupe_images/finder.rb, line 101 def without_duplicates puts "\tNo files have been detectad as duplicates" end