require 'to_regexp'
module Html2rss
module AttributePostProcessors
##
#
# Imagine this HTML:
#
Foo bar and boo
#
# YAML usage example:
# selectors:
# title:
# selector: h1
# post_process:
# name: gsub
# pattern: boo
# replacement: baz
#
# Would return:
# 'Foo bar and baz'
#
# `pattern` can be a Regexp or a String.
#
# `replacement` can be a String or a Hash.
#
# See the doc on [String#gsub](https://ruby-doc.org/core/String.html#method-i-gsub) for more info.
class Gsub
def initialize(value, env)
@value = value
options = env[:options]
@pattern = options[:pattern].to_regexp || options[:pattern]
@replacement = options[:replacement]
end
##
# @return [String]
def get
@value.to_s.gsub(@pattern, @replacement)
end
end
end
end