Class: MagicShelf::FileNameValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/magicshelf/filenamevalidator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFileNameValidator

Returns a new instance of FileNameValidator.



8
9
10
# File 'lib/magicshelf/filenamevalidator.rb', line 8

def initialize()
  @erase_original = true
end

Instance Attribute Details

#workdirObject

Returns the value of attribute workdir.



7
8
9
# File 'lib/magicshelf/filenamevalidator.rb', line 7

def workdir
  @workdir
end

Instance Method Details

#enterObject



12
13
14
# File 'lib/magicshelf/filenamevalidator.rb', line 12

def enter()
  yield
end

#processObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/magicshelf/filenamevalidator.rb', line 16

def process()
  @workdir ||= Dir.pwd
  Dir.glob(File.join(@workdir,'**/*')).select{|f|File.file?(f)}.each do |f|
    dirname = File.dirname(f)
    basename = File.basename(f,'.*')
    extname = File.extname(f)
    newbasename = basename.gsub(/#/, '_').gsub(/\+/, '_')
    if not (basename == newbasename)
      newfilename = File.join(dirname, newbasename + extname)
      FileUtils.mv(f, newfilename)
      MagicShelf.logger.info("move #{f} to #{newfilename}.")
    end
  end
end