Module: EbooksRenamer
- Defined in:
- lib/ebooks_renamer/cli.rb,
lib/ebooks_renamer/logger.rb,
lib/ebooks_renamer/version.rb,
lib/ebooks_renamer/pdf_parser.rb,
lib/ebooks_renamer/epub_parser.rb,
lib/ebooks_renamer/mobi_parser.rb,
lib/ebooks_renamer/ebooks_renamer.rb
Defined Under Namespace
Classes: CLI, EpubParser, MobiParser, Parser, PdfParser
Constant Summary collapse
- VERSION =
'0.1.0'- CustomError =
Class.new(StandardError)
Class Attribute Summary collapse
-
.logger ⇒ Logger
The logger for the project.
Class Method Summary collapse
Class Attribute Details
.logger ⇒ Logger
Returns the logger for the project.
6 7 8 |
# File 'lib/ebooks_renamer/logger.rb', line 6 def logger @logger ||= Logger.new STDOUT end |
Class Method Details
.rename(options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ebooks_renamer/ebooks_renamer.rb', line 14 def rename( = {}) files = CodeLister.files() files.each_with_index do |file, index| # process as many files as possible begin new_name = formatted_name(file, [:sep_string]) if file != new_name puts "#{index + 1} of #{files.length}: Old name: '#{file}'" puts "#{index + 1} of #{files.length}: New name: '#{new_name}'" FileUtils.mv(file, new_name) if [:commit] else puts "#{index + 1} of #{files.length}: Result : '#{file}' is identical so no action taken." end rescue Exception => e puts "Skip file '#{file}'" puts "Due to the unexpected error: #{e.message}" next end end unless [:commit] puts '------------------------------------------------------------------' puts 'This is a dry run only, to actually rename please specify --commit' puts '------------------------------------------------------------------' end end |