Class: DirProcessor

Inherits:
Object
  • Object
show all
Defined in:
lib/tree_visitor/dir_processor.rb

Instance Method Summary collapse

Constructor Details

#initialize(dirname, &action) ⇒ DirProcessor

Returns a new instance of DirProcessor.



5
6
7
8
9
# File 'lib/tree_visitor/dir_processor.rb', line 5

def initialize( dirname, &action )
  @dirname = dirname
  @processors = {}
  @default_processor = action
end

Instance Method Details

#add_processor(re, &action) ⇒ Object



11
12
13
# File 'lib/tree_visitor/dir_processor.rb', line 11

def add_processor( re, &action )
  @processors[ re ] = action
end

#runObject



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/tree_visitor/dir_processor.rb', line 15

def run()
  old_dirname = Dir.pwd
  Dir.chdir( @dirname )
  Dir["**/*"].each { |f|
    pn = Pathname.new( f ).expand_path
    # puts "#{self.class.name}#loadfromdir #{f}"

    next if pn.directory?
    process_file( pn )
  }
  Dir.chdir( old_dirname )
  self
end