Class: Deblank::Application
- Inherits:
-
Object
- Object
- Deblank::Application
- 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}
Instance Method Summary collapse
-
#initialize ⇒ Application
constructor
A new instance of Application.
-
#run! ⇒ Object
The main program.
Constructor Details
#initialize ⇒ Application
Returns a new instance of Application.
186 187 188 189 190 191 192 193 194 195 |
# File 'lib/deblank.rb', line 186 def initialize begin = Optionparser.parse!(ARGV) rescue => e usage_fail(e.) end @files = [:files] @simulate = [:simulate] @converter = NameConverter.new end |
Instance Method Details
#run! ⇒ Object
The main program.
198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/deblank.rb', line 198 def run! = "This is a dry run, files will not be renamed." warn "#{}\n#{'-' * .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 |