Class: FileRenamer::Renamer

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

Constant Summary collapse

SLASH =
Gem.win_platform? ? '\\' : '/'
FILENAME_REGEXP =
/^[a-zA-Z_0-9 -]+$/
EXTENSION_REGEXP =
/^[a-zA-Z0-9]{1,4}$/

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Renamer

Returns a new instance of Renamer.



18
19
20
21
# File 'lib/file_renamer.rb', line 18

def initialize(params)
  @params = params 
  @paths = []
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



10
11
12
# File 'lib/file_renamer.rb', line 10

def params
  @params
end

#pathsObject (readonly)

Returns the value of attribute paths.



10
11
12
# File 'lib/file_renamer.rb', line 10

def paths
  @paths
end

Class Method Details

.rename!(params) ⇒ Object



12
13
14
15
16
# File 'lib/file_renamer.rb', line 12

def self.rename!(params)
  session =  FileRenamer::Renamer.new(params)
  session.get_paths
  session.rename_files
end

Instance Method Details

#get_pathsObject



23
24
25
26
27
28
29
# File 'lib/file_renamer.rb', line 23

def get_paths
  params_correction!

  Dir["#{params[:dir]}*"].sort.each do |path|
    @paths << FileRenamer::Path.new(path, params) 
  end 
end

#rename_filesObject



31
32
33
# File 'lib/file_renamer.rb', line 31

def rename_files
  @paths.each { |p| p.rename_file! if p.correct_path? }
end