Class: Remi::Transform::Replace

Inherits:
Remi::Transform show all
Defined in:
lib/remi/transform.rb

Overview

Public: Replaces one substring with another.

to_replace - The string or regex to be replaced. repalce_with - The value to substitute.

Examples:

Replace.new(/\s/, '-').to_proc.call('hey jude') #=> 'hey-jude'

Instance Attribute Summary

Attributes inherited from Remi::Transform

#multi_args, #source_metadata, #target_metadata

Instance Method Summary collapse

Methods inherited from Remi::Transform

#call, #to_proc

Constructor Details

#initialize(to_replace, replace_with, *args, **kargs, &block) ⇒ Replace

Returns a new instance of Replace.



424
425
426
427
428
# File 'lib/remi/transform.rb', line 424

def initialize(to_replace, replace_with, *args, **kargs, &block)
  super
  @to_replace   = to_replace
  @replace_with = replace_with
end

Instance Method Details

#transform(value) ⇒ Object



430
431
432
# File 'lib/remi/transform.rb', line 430

def transform(value)
  (value || '').gsub(@to_replace, @replace_with)
end