Class: MagicShelf::FileNameValidator
- Inherits:
-
Object
- Object
- MagicShelf::FileNameValidator
- Defined in:
- lib/magicshelf/filenamevalidator.rb
Instance Attribute Summary collapse
-
#workdir ⇒ Object
Returns the value of attribute workdir.
Instance Method Summary collapse
- #enter ⇒ Object
-
#initialize ⇒ FileNameValidator
constructor
A new instance of FileNameValidator.
- #process ⇒ Object
Constructor Details
#initialize ⇒ FileNameValidator
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
#workdir ⇒ Object
Returns the value of attribute workdir.
7 8 9 |
# File 'lib/magicshelf/filenamevalidator.rb', line 7 def workdir @workdir end |
Instance Method Details
#enter ⇒ Object
12 13 14 |
# File 'lib/magicshelf/filenamevalidator.rb', line 12 def enter() yield end |
#process ⇒ Object
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 |