Class: Vera::Renamer
- Inherits:
-
Object
- Object
- Vera::Renamer
- Defined in:
- lib/vera/renamer.rb
Class Method Summary collapse
- .exclude_already_renamed_files(files) ⇒ Object
- .execute(options) ⇒ Object
- .rename(path) ⇒ Object
- .rename_files_with_date(path, ext, date_property) ⇒ Object
Class Method Details
.exclude_already_renamed_files(files) ⇒ Object
39 40 41 |
# File 'lib/vera/renamer.rb', line 39 def self.exclude_already_renamed_files(files) files.select { |f| f[:filename].match(/\d+-\d+-\d+-/).nil? } end |
.execute(options) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/vera/renamer.rb', line 5 def self.execute() unless Exiftool.installed? puts ''" You need to install exiftool to use vera. You can run the following command to do it: bash <(curl -Ls https://git.io/JtbuH) "'' return end path = .path path = Dir.pwd if .path.nil? path = File.(path) rename path end |
.rename(path) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/vera/renamer.rb', line 19 def self.rename(path) rename_files_with_date path, 'ARW', 'DateTimeOriginal' rename_files_with_date path, 'JPG', 'DateTimeOriginal' rename_files_with_date path, 'HEIC', 'DateTimeOriginal' rename_files_with_date path, 'MOV', 'CreationDate' rename_files_with_date path, 'MP4', 'MediaCreateDate' end |
.rename_files_with_date(path, ext, date_property) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/vera/renamer.rb', line 27 def self.rename_files_with_date(path, ext, date_property) puts "#{Icons.check} Adding creation date to #{ext} files in the filename" files = Lister.all_files(path, ext) files = Renamer.exclude_already_renamed_files(files) if files.empty? puts "No files to rename for #{ext} file type." return end files_string = files.map { |f| "\"#{f[:path]}\"" }.join(' ') puts "#{Icons.cross} Something went wrong" unless Exiftool.change_filename_with_date(date_property, files_string) end |