Class: Realize::Format::StringReplace
- Inherits:
-
Object
- Object
- Realize::Format::StringReplace
- Defined in:
- lib/realize/format/string_replace.rb
Overview
This transformer takes in a value and replaces all occurrences of the given original pattern with the replacement pattern.
Instance Attribute Summary collapse
-
#original ⇒ Object
readonly
Returns the value of attribute original.
-
#replacement ⇒ Object
readonly
Returns the value of attribute replacement.
Instance Method Summary collapse
-
#initialize(original:, replacement:) ⇒ StringReplace
constructor
A new instance of StringReplace.
- #transform(_resolver, value, _time, _record) ⇒ Object
Constructor Details
#initialize(original:, replacement:) ⇒ StringReplace
Returns a new instance of StringReplace.
19 20 21 22 23 24 25 26 |
# File 'lib/realize/format/string_replace.rb', line 19 def initialize(original:, replacement:) raise ArgumentError, 'original is required' if original.to_s.empty? @original = original @replacement = replacement.to_s freeze end |
Instance Attribute Details
#original ⇒ Object (readonly)
Returns the value of attribute original.
17 18 19 |
# File 'lib/realize/format/string_replace.rb', line 17 def original @original end |
#replacement ⇒ Object (readonly)
Returns the value of attribute replacement.
17 18 19 |
# File 'lib/realize/format/string_replace.rb', line 17 def replacement @replacement end |
Instance Method Details
#transform(_resolver, value, _time, _record) ⇒ Object
28 29 30 |
# File 'lib/realize/format/string_replace.rb', line 28 def transform(_resolver, value, _time, _record) value.to_s.gsub(original, replacement) end |