Class: MetadataCleaner::Cleaner
- Inherits:
-
Object
- Object
- MetadataCleaner::Cleaner
- Defined in:
- lib/metadata_cleaner/cleaner.rb
Constant Summary collapse
- IMAGE_FORMATS =
'gif,png,jpeg,jpg,JPG,GIF,PNG,JPEG,TIFF,TIF,tif,tiff,SVG,svg'
Instance Attribute Summary collapse
-
#images ⇒ Object
Returns the value of attribute images.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #convert(options = {}) ⇒ Object
- #dirsize(options = {}) ⇒ Object
-
#initialize(path) ⇒ Cleaner
constructor
A new instance of Cleaner.
- #log(message) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(path) ⇒ Cleaner
Returns a new instance of Cleaner.
8 9 10 11 12 |
# File 'lib/metadata_cleaner/cleaner.rb', line 8 def initialize(path) @path = path image_files = File.join(@path, "**", "*.{#{IMAGE_FORMATS}}") @images = Dir.glob(image_files) end |
Instance Attribute Details
#images ⇒ Object
Returns the value of attribute images.
6 7 8 |
# File 'lib/metadata_cleaner/cleaner.rb', line 6 def images @images end |
#path ⇒ Object
Returns the value of attribute path.
6 7 8 |
# File 'lib/metadata_cleaner/cleaner.rb', line 6 def path @path end |
Instance Method Details
#convert(options = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/metadata_cleaner/cleaner.rb', line 37 def convert(={}) total_length = @images.size.to_f @images.each_with_index do |file, index| system "convert #{file} -strip #{file}" print "\r\t-processed: %3i%%" % (100*(index.to_f+1.0)/total_length) end log '' end |
#dirsize(options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/metadata_cleaner/cleaner.rb', line 27 def dirsize(={}) size = 0 @images.each do |f| size += File.stat(f).size end size/(1024*1024.0) end |
#log(message) ⇒ Object
47 48 49 |
# File 'lib/metadata_cleaner/cleaner.rb', line 47 def log() STDOUT.puts end |
#start ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/metadata_cleaner/cleaner.rb', line 14 def start before_size = dirsize log "#{before_size} Mb" convert after_size = dirsize log "#{after_size} Mb" percent = ((before_size - after_size)/before_size)*100 log "Optimization result: #{percent} %" end |