Module: VixenRename::Util

Included in:
Client
Defined in:
lib/vixen_rename/util.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#rename(old_name, new_name, date, verbose: true) ⇒ Object

rubocop:disable Metrics/MethodLength

Parameters:

  • old_name (String)
  • new_name (String)
  • date (Date)
  • verbose (Boolean) (defaults to: true)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/vixen_rename/util.rb', line 11

def rename(old_name, new_name, date, verbose: true)
  if verbose
    print "File Match: #{old_name.to_s.colorize(:red)} " \
          "can be renamed to #{new_name.to_s.colorize(:green)}\n"
  else
    begin
      # Rename the file
      File.rename(old_name, new_name)

      # Update the modified time of the file to the date the scene was
      # released and keep the accessed time as it is
      File.utime(File.atime(new_name), date, new_name)
      print "File Match: #{old_name.to_s.colorize(:red)} " \
            "renamed to #{new_name.to_s.colorize(:green)}\n"
    rescue Errno::ENAMETOOLONG
      print "Generated name is too long. Skip processing.\n"
    end
  end
end