Class: Lara::FileTools::Renamer

Inherits:
Object
  • Object
show all
Defined in:
lib/lara/file_tools/renamer.rb

Instance Method Summary collapse

Constructor Details

#initialize(dir = ".") ⇒ Renamer

Returns a new instance of Renamer.



4
5
6
7
# File 'lib/lara/file_tools/renamer.rb', line 4

def initialize(dir = ".")
  @dir = dir
  @count = 0
end

Instance Method Details

#append(pattern) ⇒ Object



13
14
15
# File 'lib/lara/file_tools/renamer.rb', line 13

def append(pattern)
  apply { |f| "#{f.sub(/\.\w+$/, "")}_#{pattern}#{File.extname(f)}" }
end

#prepend(pattern) ⇒ Object



9
10
11
# File 'lib/lara/file_tools/renamer.rb', line 9

def prepend(pattern)
  apply { |f| "#{pattern}_#{f}" }
end

#replace(old, new) ⇒ Object



17
18
19
# File 'lib/lara/file_tools/renamer.rb', line 17

def replace(old, new)
  apply { |f| f.sub(old, new) }
end

#sequence(format = "file_%03d") ⇒ Object



21
22
23
24
# File 'lib/lara/file_tools/renamer.rb', line 21

def sequence(format = "file_%03d")
  i = 0
  apply { |f| i += 1; "#{format % i}#{File.extname(f)}" }
end