Class: Deblank::Application

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

Overview

The main program. It’s run! method is called if the script is run from the command line. It parses the command line arguments and renames the files.

Constant Summary collapse

ERRORCODE =
{ general: 1, usage: 2 }.freeze

Instance Method Summary collapse

Constructor Details

#initializeApplication

Returns a new instance of Application.



187
188
189
190
191
192
193
194
195
196
# File 'lib/deblank.rb', line 187

def initialize
  begin
    options = Optionparser.parse!(ARGV)
  rescue StandardError => e
    usage_fail(e.message)
  end
  @files = options[:files]
  @simulate = options[:simulate]
  @converter = NameConverter.new
end

Instance Method Details

#run!Object

The main program.



199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/deblank.rb', line 199

def run!
  message = "This is a dry run, files will not be renamed."
  warn "#{message}\n#{'-' * message.size}\n"  if @simulate

  @files.each do |filename|
    next  unless file_exist?(filename)
    next  unless invalid?(filename)

    new_filename = @converter.convert(filename)
    secure_rename(filename, new_filename)
  end
end