Class: Html2rss::AttributePostProcessors::Gsub

Inherits:
Object
  • Object
show all
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. 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](ruby-doc.org/core/String.html#method-i-gsub) for more info.

Instance Method Summary collapse

Constructor Details

#initialize(value, context) ⇒ Gsub

Returns a new instance of Gsub.

Parameters:



32
33
34
35
# File 'lib/html2rss/attribute_post_processors/gsub.rb', line 32

def initialize(value, context)
  @value = value
  @options = context[:options]
end

Instance Method Details

#getString

Returns:

  • (String)


39
40
41
# File 'lib/html2rss/attribute_post_processors/gsub.rb', line 39

def get
  @value.to_s.gsub(pattern, replacement)
end