Class: AstroSubframeOrganizer::Utils::Unorganizer
- Inherits:
-
Object
- Object
- AstroSubframeOrganizer::Utils::Unorganizer
- Includes:
- Logging
- Defined in:
- lib/astro_subframe_organizer/utils/unorganizer.rb
Overview
Moves all FITS and CR2 files from subdirectories back into the target directory. Useful for undoing an organize run so files can be re-organized with different settings.
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path = Dir.pwd) ⇒ Unorganizer
constructor
A new instance of Unorganizer.
- #unorganize(dry_run: false, verbose: false) ⇒ Object
Methods included from Logging
Constructor Details
#initialize(path = Dir.pwd) ⇒ Unorganizer
Returns a new instance of Unorganizer.
12 13 14 |
# File 'lib/astro_subframe_organizer/utils/unorganizer.rb', line 12 def initialize(path = Dir.pwd) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
10 11 12 |
# File 'lib/astro_subframe_organizer/utils/unorganizer.rb', line 10 def path @path end |
Instance Method Details
#unorganize(dry_run: false, verbose: false) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/astro_subframe_organizer/utils/unorganizer.rb', line 16 def unorganize(dry_run: false, verbose: false) files = find_organized_files if files.empty? logger.info 'No organized files found.' return end logger.info "Preparing to move #{files.size} files to #{path}..." = TTY::ProgressBar.new('Moving files [:bar] :current/:total (:percent) :eta', total: files.size) files.each do |file| dest = File.join(path, File.basename(file)) if File.exist?(dest) .log "Skipping #{File.basename(file)}, already exists in #{path}." next end FileUtils.mv(file, dest, verbose: verbose || dry_run, noop: dry_run) .advance(1) end cleanup_empty_dirs(dry_run: dry_run) unless dry_run end |