Class: AstroSubframeOrganizer::Utils::ThumbnailCleaner

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/astro_subframe_organizer/utils/thumbnail_cleaner.rb

Overview

A cleanup utility that removes thumbnail images with filenames mattching ‘pattern` from `path` and all its subdirectories.

Constant Summary collapse

ASIAIR_THUMBNAIL_PATTERN =
'**/**_thn.jpg'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#logger

Constructor Details

#initialize(path = Dir.pwd) ⇒ ThumbnailCleaner

Returns a new instance of ThumbnailCleaner.



14
15
16
# File 'lib/astro_subframe_organizer/utils/thumbnail_cleaner.rb', line 14

def initialize(path = Dir.pwd)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



12
13
14
# File 'lib/astro_subframe_organizer/utils/thumbnail_cleaner.rb', line 12

def path
  @path
end

Instance Method Details

#cleanup(pattern: ASIAIR_THUMBNAIL_PATTERN, dry_run: false, verbose: false) ⇒ Object

Removes all the jpg thumbnails under the given directory.



19
20
21
22
23
# File 'lib/astro_subframe_organizer/utils/thumbnail_cleaner.rb', line 19

def cleanup(pattern: ASIAIR_THUMBNAIL_PATTERN, dry_run: false, verbose: false)
  logger.info 'Removing jpg thumbnails...'
  Dir.glob([pattern], base: path)
     .each { |thumbnail| FileUtils.rm File.join(path, thumbnail), noop: dry_run, verbose: verbose }
end