Class: Awestruct::Extensions::Gsub
- Inherits:
-
Object
- Object
- Awestruct::Extensions::Gsub
- Defined in:
- lib/awestruct/extensions/gsub.rb
Instance Method Summary collapse
-
#initialize(pattern, replacement, options = {}) ⇒ Gsub
constructor
A new instance of Gsub.
- #transform(site, page, rendered) ⇒ Object
Constructor Details
#initialize(pattern, replacement, options = {}) ⇒ Gsub
Returns a new instance of Gsub.
5 6 7 8 9 |
# File 'lib/awestruct/extensions/gsub.rb', line 5 def initialize(pattern, replacement, = {}) @pattern = pattern @replacement = replacement.is_a?(Proc) ? replacement : lambda { |site, page| replacement } @gsub_required = lambdaize([:gsub_required]) end |
Instance Method Details
#transform(site, page, rendered) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/awestruct/extensions/gsub.rb', line 11 def transform(site, page, rendered) if (@gsub_required.call(site, page)) replacement = @replacement.call(site, page).to_s rendered = rendered.gsub(@pattern, replacement) end rendered end |