Class: FileRenamer::Renamer
- Inherits:
-
Object
- Object
- FileRenamer::Renamer
- 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
-
#params ⇒ Object
readonly
Returns the value of attribute params.
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
Class Method Summary collapse
Instance Method Summary collapse
- #get_paths ⇒ Object
-
#initialize(params) ⇒ Renamer
constructor
A new instance of Renamer.
- #rename_files ⇒ Object
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
#params ⇒ Object (readonly)
Returns the value of attribute params.
10 11 12 |
# File 'lib/file_renamer.rb', line 10 def params @params end |
#paths ⇒ Object (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_paths ⇒ Object
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_files ⇒ Object
31 32 33 |
# File 'lib/file_renamer.rb', line 31 def rename_files @paths.each { |p| p.rename_file! if p.correct_path? } end |