class FileScanner
Public Class Methods
new(directory, output_file, verbose)
click to toggle source
# File lib/file_scanner.rb, line 8 def initialize(directory, output_file, verbose) @directory = Pathname.new(directory) @output_file = output_file @verbose = verbose @allowed_formats = %w{.jpg .jpeg} end
Public Instance Methods
begin_scan()
click to toggle source
# File lib/file_scanner.rb, line 15 def begin_scan directory_scanning(@directory) end
Private Instance Methods
directory_scanning(dir)
click to toggle source
Recursively scans directory searching for image files
# File lib/file_scanner.rb, line 22 def directory_scanning(dir) Extractor.new.show_throughput("scanning path: #{dir}", @verbose) dir.children.each do |child| if child.file? && @allowed_formats.include?(File.extname(child).downcase) begin @output_file.insert(ImageReader.new(child.to_path).restructure) rescue EXIFR::MalformedJPEG => e Extractor.new.show_throughput("Unprocessable image: #{child.to_path}", @verbose) Extractor.new.show_throughput(e.message, @verbose) rescue SystemCallError => e Extractor.new.show_throughput("An error occurred while processing image: #{child.to_path}", @verbose) raise SystemCallError, "The error received was: #{e}" end elsif child.directory? begin directory_scanning(child) rescue SystemCallError => e Extractor.new.show_throughput("Unable to scan sub directory: #{child.to_path}", @verbose) Extractor.new.show_throughput(e.message, @verbose) end end end end