Sha256: e2ef10d23254974cea54b91a9c573dbbd1075846103c2f2ce39e111fa43067eb

Contents?: true

Size: 818 Bytes

Versions: 1

Compression:

Stored size: 818 Bytes

Contents

require_relative 'fshelpyhelp'

module Stowaway
  class Sweeper
    include FSHelpyHelp

    def initialize(files_to_find, ext_to_ignore = nil)
      @files_to_find = files_to_find
      @ignore = ext_to_ignore || [/^\.|\.jpg$|\.gif$|.png$/i]
    end
  
    def inspect_file(file)
      File.open(file, 'r') do |i|
        while line = i.gets
          remove_match(line)
        end
      end
    end

    def remove_match(line)
      @files_to_find.delete_if { |file| line.include?(file.name) }
    end
  
    def sweep(path)
      dir = Dir.new(path)
    
      dir.each do |f|
        next if ignore?(f)
      
        file = File.join(dir.path, f)
      
        if File.directory?(file)
          sweep(file)
        else
          inspect_file(file)
        end
      end
      @files_to_find
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stowaway-0.0.4 lib/stowaway/sweeper.rb