Module: Drakkon::Images::DowncaseNormalize
- Defined in:
- lib/drakkon/lib/images/downcase_normalize.rb
Overview
This downcases all the things
Class Method Summary collapse
- .images ⇒ Object
-
.process(file) ⇒ Object
Image file name normalization.
- .prompt ⇒ Object
- .run!(_args = nil) ⇒ Object
- .start ⇒ Object
Class Method Details
.images ⇒ Object
59 60 61 |
# File 'lib/drakkon/lib/images/downcase_normalize.rb', line 59 def self.images Dir["#{Dir.pwd}/*.png"] + Dir["#{Dir.pwd}/*.PNG"] end |
.process(file) ⇒ Object
Image file name normalization. Downcase and replace spaces with underscore
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/drakkon/lib/images/downcase_normalize.rb', line 40 def self.process(file) new_name = File.basename(file).downcase.gsub(' ', '_').gsub('(', '_').gsub(')', '_').gsub('-', '_') path = File.dirname(file) # Remove Final Underscore last char of basename is an underscore ext = File.extname(new_name) basename = File.basename(new_name, ext) if basename[-1] == '_' && basename.length > 1 new_name = basename[0..-2] new_name += ext end # Skip if the same return if new_name == File.basename(file) LogBot.info('Image Downcase Normalize', "Old: #{File.basename(file)}, New: #{new_name}") FileUtils.mv(file, "#{path}/#{new_name}") end |
.prompt ⇒ Object
63 64 65 |
# File 'lib/drakkon/lib/images/downcase_normalize.rb', line 63 def self.prompt TTY::Prompt.new(active_color: :cyan, interrupt: :exit) end |
.run!(_args = nil) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/drakkon/lib/images/downcase_normalize.rb', line 5 def self.run!(_args = nil) puts <<~HELP - Run in the directory you wish to rename images - Downcase - Normalize - To Underscores: - Space - Perentheses - Dash - Delete Final Chars - If Underscore Current Directory; #{Dir.pwd.pastel(:yellow)} Images: HELP images.each do |img| img_s = img.gsub("#{Dir.pwd}/", '').pastel(:yellow) puts " - #{img_s}" end puts exit unless prompt.yes? "#{'Are you sure?'.pastel(:bright_yellow)} Rename!? #{'(Destructive)'.pastel(:red)}" start end |
.start ⇒ Object
33 34 35 36 37 |
# File 'lib/drakkon/lib/images/downcase_normalize.rb', line 33 def self.start images.each do |img| process(img) end end |