Class: Fixnames::Engine
- Inherits:
-
Object
- Object
- Fixnames::Engine
- Includes:
- Debug, Filters, Helpers
- Defined in:
- lib/fixnames/engine.rb,
lib/fixnames/engine/scan_dir.rb
Overview
the main filtering-engine that fixes a single filename
Defined Under Namespace
Classes: ScanDir
Instance Attribute Summary (collapse)
-
- (Object) dir
readonly
Returns the value of attribute dir.
-
- (Object) fixed
(also: #to_s)
readonly
Returns the value of attribute fixed.
-
- (Object) option
readonly
Returns the value of attribute option.
-
- (Object) orig
readonly
Returns the value of attribute orig.
Instance Method Summary (collapse)
- - (Boolean) changed?
- - (Boolean) collision?
- - (Object) fix!
- - (Object) fixed_path
-
- (Engine) initialize(name, opts = Option.new)
constructor
Creates an engine to fix a single filename.
- - (Object) orig_path
- - (Boolean) scandir_changed?
Methods included from Filters
#banners, #brackets, #camelcase, #charstrip, #checksums, #expunge, #fix_dashes, #fix_dots, #hack_and, #junkwords, #lowercase, #semicolon, #whitespace
Methods included from Helpers
#match_bracket_close, #match_bracket_open, #remove, #remove_bracket_characters_from, #remove_bracket_ranges, #replace, #translate, #wrap_brackets
Methods included from Debug
#bold, #debug, #info, #note, #warn
Constructor Details
- (Engine) initialize(name, opts = Option.new)
Creates an engine to fix a single filename.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/fixnames/engine.rb', line 21 def initialize(name, opts=Option.new) @option = opts @dir = File.dirname(name) @orig = File.basename(name) if option.recursive && File.directory?(@orig) @scandir = ScanDir.new(@orig, option) end @fixed = @orig.dup option.filter_order.each do |optname| if option.send(optname) and respond_to?(optname) debug "FILTER[:#{optname}]" old = fixed.dup case method(optname).arity when 1 then send optname, option.send(optname) when 0 then send optname else raise "Unsupported arity in ##{optname}" end if old != fixed debug "\t old -- #{old.inspect}" debug "\t new -- #{fixed.inspect}" end end end end |
Instance Attribute Details
- (Object) dir (readonly)
Returns the value of attribute dir
14 15 16 |
# File 'lib/fixnames/engine.rb', line 14 def dir @dir end |
- (Object) fixed (readonly) Also known as: to_s
Returns the value of attribute fixed
14 15 16 |
# File 'lib/fixnames/engine.rb', line 14 def fixed @fixed end |
- (Object) option (readonly)
Returns the value of attribute option
14 15 16 |
# File 'lib/fixnames/engine.rb', line 14 def option @option end |
- (Object) orig (readonly)
Returns the value of attribute orig
14 15 16 |
# File 'lib/fixnames/engine.rb', line 14 def orig @orig end |
Instance Method Details
- (Boolean) changed?
62 63 64 |
# File 'lib/fixnames/engine.rb', line 62 def changed? fixed != orig end |
- (Boolean) collision?
66 67 68 |
# File 'lib/fixnames/engine.rb', line 66 def collision? File.exists? fixed_path end |
- (Object) fix!
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/fixnames/engine.rb', line 70 def fix! @scandir.fix! if @scandir if changed? if collision? warn "NAME COLLISION: #{fixed_path.inspect}" else note "mv #{orig_path.inspect} #{fixed_path.inspect}" File.rename orig_path, fixed_path unless option.pretend end else info "no change: #{orig_path.inspect}" end self end |
- (Object) fixed_path
54 55 56 |
# File 'lib/fixnames/engine.rb', line 54 def fixed_path "#{dir}/#{fixed}" end |
- (Object) orig_path
50 51 52 |
# File 'lib/fixnames/engine.rb', line 50 def orig_path "#{dir}/#{orig}" end |
- (Boolean) scandir_changed?
58 59 60 |
# File 'lib/fixnames/engine.rb', line 58 def scandir_changed? @scandir ? @scandir.changed? : false end |