class Nrename::NumberedFile
Attributes
dir[R]
path[R]
Public Class Methods
new(path, dir)
click to toggle source
# File lib/nrename/numbered_file.rb, line 14 def initialize(path, dir) @path = path @dir = dir end
Public Instance Methods
adjusted_number()
click to toggle source
# File lib/nrename/numbered_file.rb, line 55 def adjusted_number number.to_s.rjust num_field_length, '0' end
normalize()
click to toggle source
# File lib/nrename/numbered_file.rb, line 27 def normalize rename_to normalized_path end
normalized_path()
click to toggle source
# File lib/nrename/numbered_file.rb, line 40 def normalized_path dirname, filename = path.split new_filename = filename.to_s if options.numbers_only name = adjusted_number extname = filename.extname new_filename = "#{name}#{extname}" else new_filename[options.pattern, 1] = adjusted_number end dirname + new_filename end
number()
click to toggle source
# File lib/nrename/numbered_file.rb, line 19 def number @number ||= options.renumber ? counter.next : number_from_path end
number_from_path()
click to toggle source
# File lib/nrename/numbered_file.rb, line 23 def number_from_path path.basename.to_s[options.pattern, 1].to_i end
rename_to(new_name)
click to toggle source
# File lib/nrename/numbered_file.rb, line 31 def rename_to(new_name) return if path == new_name FileUtils.mv path, new_name, { :noop => !options.execute, :verbose => options.verbose } end