Class: BatchRename::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/batch_rename/cli.rb

Constant Summary collapse

EXIT_CODE_SUCCESS =
0
EXIT_CODE_FAILURE =
1
EDITOR =
Editor::DiffMerge
INSTRUCTIONS =
{
  :before => "Original file names – do not edit the field below",
  :after => "Rename your files below. Press ⌘S to save, ⌘Q to quit"
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#catalogsObject (readonly)

Returns the value of attribute catalogs.



17
18
19
# File 'lib/batch_rename/cli.rb', line 17

def catalogs
  @catalogs
end

#diff_tmp_dirObject (readonly)

Returns the value of attribute diff_tmp_dir.



17
18
19
# File 'lib/batch_rename/cli.rb', line 17

def diff_tmp_dir
  @diff_tmp_dir
end

Class Method Details

.run!Object



19
20
21
22
23
24
25
26
27
# File 'lib/batch_rename/cli.rb', line 19

def self.run!
  begin
    CLI::new.run!
    exit EXIT_CODE_SUCCESS
  rescue Editor::EditorNotFoundError => e
    warn e.message
    exit EXIT_CODE_FAILURE
  end
end

Instance Method Details

#run!Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/batch_rename/cli.rb', line 29

def run!
  caption = "batch_rename v#{VERSION} - #{ Dir.pwd }"
  write_catalog_files!

  puts 'Launching graphical editor…'
  result = EDITOR.new(catalogs, caption).launch!.result

  puts "Renaming #{ result.modified_count } file(s)"
  puts rename!(result)
end