Class: Html2rss::Selectors::PostProcessors::Gsub
- Defined in:
- lib/html2rss/selectors/post_processors/gsub.rb
Overview
Imagine this HTML:
<h1>Foo 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. If it is a String, it will remove
one pair of surrounding slashes ('/') to keep backwards compatibility
and then parse it to build a Regexp.
replacement can be a String or a Hash.
See the doc on String#gsub for more info.
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
- #get ⇒ String
-
#initialize(value, context) ⇒ Gsub
constructor
A new instance of Gsub.
Methods inherited from Base
Constructor Details
#initialize(value, context) ⇒ Gsub
Returns a new instance of Gsub.
41 42 43 44 45 46 47 48 |
# File 'lib/html2rss/selectors/post_processors/gsub.rb', line 41 def initialize(value, context) super = context[:options] @replacement = [:replacement] @pattern = [:pattern] end |
Class Method Details
.validate_args!(value, context) ⇒ Object
32 33 34 35 36 |
# File 'lib/html2rss/selectors/post_processors/gsub.rb', line 32 def self.validate_args!(value, context) assert_type value, String, :value, context: (i[replacement pattern], context) assert_type context.dig(:options, :replacement), [String, Hash], :replacement, context: end |
Instance Method Details
#get ⇒ String
52 53 54 |
# File 'lib/html2rss/selectors/post_processors/gsub.rb', line 52 def get value.to_s.gsub(pattern, replacement) end |