Class: Renamr::SubstituteAction

Inherits:
Action
  • Object
show all
Defined in:
lib/renamr/substitute.rb

Overview

Substitutes a string with a string.

Instance Method Summary collapse

Methods inherited from Action

#p2m, #set

Constructor Details

#initialize(src, dst) ⇒ SubstituteAction

Returns a new instance of SubstituteAction.



11
12
13
14
15
16
17
# File 'lib/renamr/substitute.rb', line 11

def initialize(src, dst)
  raise 'src cannot be nil.' if src.nil?

  # The action works after PointAction. All points are replaces with minus.
  @src = p2m(src)
  @dst = dst.nil? ? '-' : p2m(dst)
end

Instance Method Details

#do(src) ⇒ Object



19
20
21
# File 'lib/renamr/substitute.rb', line 19

def do(src)
  src.gsub(@src, @dst)
end