Class: Html2rss::AttributePostProcessors::Gsub
- Inherits:
-
Object
- Object
- Html2rss::AttributePostProcessors::Gsub
- Defined in:
- lib/html2rss/attribute_post_processors/gsub.rb
Overview
Imagine this HTML:
<h1>Foo bar and boo<h1>
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](ruby-doc.org/core/String.html#method-i-gsub) for more info.
Instance Method Summary collapse
- #get ⇒ String
-
#initialize(value, env) ⇒ Gsub
constructor
A new instance of Gsub.
Constructor Details
#initialize(value, env) ⇒ Gsub
Returns a new instance of Gsub.
28 29 30 31 32 33 |
# File 'lib/html2rss/attribute_post_processors/gsub.rb', line 28 def initialize(value, env) @value = value = env[:options] @pattern = [:pattern].to_regexp || [:pattern] @replacement = [:replacement] end |
Instance Method Details
#get ⇒ String
37 38 39 |
# File 'lib/html2rss/attribute_post_processors/gsub.rb', line 37 def get @value.to_s.gsub(@pattern, @replacement) end |