Class: Sequencer::Padder
- Inherits:
-
Object
- Object
- Sequencer::Padder
- Defined in:
- lib/sequencer/padder.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#get_renames ⇒ Object
Return an array of tuples containing /source/file/path and /destination/file/path renames.
-
#initialize(with_sequence, pad_length = nil) ⇒ Padder
constructor
A new instance of Padder.
Constructor Details
#initialize(with_sequence, pad_length = nil) ⇒ Padder
Returns a new instance of Padder.
2 3 4 5 |
# File 'lib/sequencer/padder.rb', line 2 def initialize(with_sequence, pad_length = nil) @sequence = with_sequence @padz = (pad_length || e.length.to_s.length).to_i end |
Class Method Details
.check_renames_for_dupes(renames) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/sequencer/padder.rb', line 20 def self.check_renames_for_dupes(renames) # Check for dupes destinations = renames.map{|e| e[1] } if (destinations.uniq.length != destinations.length) twice = destinations - destinations.uniq raise "Cannot rename - #{twice.join(', ')} will overwrite each other through mangled renames" end end |
Instance Method Details
#get_renames ⇒ Object
Return an array of tuples containing /source/file/path and /destination/file/path renames
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/sequencer/padder.rb', line 9 def get_renames @sequence.inject([]) do | renames, f | rep_name = f.gsub(/([\.\-\_]?)(\d+)\.(\w+)$/) do ".%0#{@padz}d.%s" % [$2.to_i, $3] end # Now this is a replaced name from_to = [File.join(e.directory, f), File.join(e.directory, rep_name)] renames.push(from_to) end end |