Class: Fec::FileExtensionChanger

Inherits:
Thor
  • Object
show all
Includes:
FileHelper, Messenger
Defined in:
lib/fec/cli.rb

Instance Method Summary collapse

Methods included from Messenger

#notice_message

Methods included from FileHelper

#directory?

Instance Method Details

#rename(folder_path) ⇒ Object


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fec/cli.rb', line 22

def rename(folder_path)
  old_extension = options.fetch('old_extension')
  new_extension = options.fetch('new_extension')

  Dir.entries("#{folder_path}/").each do |name|
    path = "#{folder_path}/#{name}"
    if directory?(path)
      notice_message("Processing #{path}")
      rename(path)
    elsif name.downcase.include? old_extension
      old_file_name = "#{folder_path}/#{name}"
      new_file_name = "#{folder_path}/#{File.basename(name, '.*')}.#{new_extension}"
      notice_message("Changing #{name}")
      FileUtils.mv old_file_name, new_file_name
    end
  end
end

#versionObject


15
16
17
# File 'lib/fec/cli.rb', line 15

def version
  puts "Fec version #{::Fec::VERSION} on Ruby #{RUBY_VERSION}"
end