Sha256: fd54adb4cd5b1b0005d91e08f7df6f25ac742091506572f11cdc1efe1da1376a

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module VixenRename
  module Util # :nodoc:

    # rubocop:disable Metrics/MethodLength
    # @param [String] old_name
    # @param [String] new_name
    # @param [Date] date
    # @param [Boolean] verbose
    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
    # rubocop:enable Metrics/MethodLength
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vixen_rename-0.1.0 lib/vixen_rename/util.rb