Class: Stowaway::Sweeper

Inherits:
Object
  • Object
show all
Includes:
FSHelpyHelp, Output
Defined in:
lib/stowaway/sweeper.rb

Overview

Sweeper will sweep through a directory recursively (path) and try to find references to files in the array of FileObjs passed in as the second parameter.

Constant Summary

Constants included from Output

Output::RESET

Instance Method Summary collapse

Methods included from Output

#clr_print, #flush, #new_line

Methods included from FSHelpyHelp

#ignore?

Constructor Details

#initialize(matcher = Matcher.new, ext_to_ignore = []) ⇒ Sweeper

Returns a new instance of Sweeper.



17
18
19
20
21
# File 'lib/stowaway/sweeper.rb', line 17

def initialize(matcher = Matcher.new, ext_to_ignore = [])
  @matcher = matcher
  @ignore = ext_to_ignore
  @ignore << /^\.|\.jpg$|\.jpeg$|\.gif$|\.png$|\.ico$|\.bmp$/i
end

Instance Method Details

#sweep(path, files = nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/stowaway/sweeper.rb', line 23

def sweep(path, files=nil)
  @root ||= path
  @result ||= OpenStruct.new({ :files => files, :name_only_matches => []})

  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
  @result
end