Class: Kscript::KkFileRenameUtils
- Inherits:
-
Base
- Object
- Base
- Kscript::KkFileRenameUtils
show all
- Defined in:
- lib/kscript/plugins/kk_file_rename_utils.rb
Instance Attribute Summary collapse
Attributes inherited from Base
#logger
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#human_output?, inherited, #with_error_handling
Constructor Details
Returns a new instance of KkFileRenameUtils.
14
15
16
17
18
19
|
# File 'lib/kscript/plugins/kk_file_rename_utils.rb', line 14
def initialize(*args, **opts)
super
@source_pattern = args[0]
@target_pattern = args[1]
@directory = args[2] || Dir.pwd
end
|
Instance Attribute Details
#directory ⇒ Object
Returns the value of attribute directory.
12
13
14
|
# File 'lib/kscript/plugins/kk_file_rename_utils.rb', line 12
def directory
@directory
end
|
#source_pattern ⇒ Object
Returns the value of attribute source_pattern.
12
13
14
|
# File 'lib/kscript/plugins/kk_file_rename_utils.rb', line 12
def source_pattern
@source_pattern
end
|
#target_pattern ⇒ Object
Returns the value of attribute target_pattern.
12
13
14
|
# File 'lib/kscript/plugins/kk_file_rename_utils.rb', line 12
def target_pattern
@target_pattern
end
|
Class Method Details
.arguments ⇒ Object
33
34
35
|
# File 'lib/kscript/plugins/kk_file_rename_utils.rb', line 33
def self.arguments
'<pattern> <replacement> [path]'
end
|
.author ⇒ Object
45
46
47
|
# File 'lib/kscript/plugins/kk_file_rename_utils.rb', line 45
def self.author
'kk'
end
|
.description ⇒ Object
49
50
51
|
# File 'lib/kscript/plugins/kk_file_rename_utils.rb', line 49
def self.description
'Batch rename files by pattern.'
end
|
.group ⇒ Object
41
42
43
|
# File 'lib/kscript/plugins/kk_file_rename_utils.rb', line 41
def self.group
'project'
end
|
.usage ⇒ Object
37
38
39
|
# File 'lib/kscript/plugins/kk_file_rename_utils.rb', line 37
def self.usage
"kscript file_rename foo bar ./src\nkscript file_rename 'test' 'prod' ~/projects"
end
|
Instance Method Details
#rename ⇒ Object
27
28
29
30
31
|
# File 'lib/kscript/plugins/kk_file_rename_utils.rb', line 27
def rename
Dir.entries(@directory).each do |filename|
process_file(filename)
end
end
|
#run ⇒ Object
21
22
23
24
25
|
# File 'lib/kscript/plugins/kk_file_rename_utils.rb', line 21
def run
with_error_handling do
rename
end
end
|