Class: Kscript::KkFileRenameUtils

Inherits:
Base
  • Object
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

#initialize(*args, **opts) ⇒ KkFileRenameUtils

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

#directoryObject (readonly)

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_patternObject (readonly)

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_patternObject (readonly)

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

.argumentsObject



33
34
35
# File 'lib/kscript/plugins/kk_file_rename_utils.rb', line 33

def self.arguments
  '<pattern> <replacement> [path]'
end

.authorObject



45
46
47
# File 'lib/kscript/plugins/kk_file_rename_utils.rb', line 45

def self.author
  'kk'
end

.descriptionObject



49
50
51
# File 'lib/kscript/plugins/kk_file_rename_utils.rb', line 49

def self.description
  'Batch rename files by pattern.'
end

.groupObject



41
42
43
# File 'lib/kscript/plugins/kk_file_rename_utils.rb', line 41

def self.group
  'project'
end

.usageObject



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

#renameObject



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

#runObject



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