Class: Html2rss::Selectors::Extractors::Html

Inherits:
Object
  • Object
show all
Defined in:
lib/html2rss/selectors/extractors/html.rb

Overview

Returns the HTML content of the specified element.

Example HTML structure:

<p>Lorem <b>ipsum</b> dolor ...</p>

YAML usage example:

selectors:
  description:
    selector: p
    extractor: html

Would return:

'<p>Lorem <b>ipsum</b> dolor ...</p>'

Always ensure to sanitize the HTML during post-processing with PostProcessors::SanitizeHtml.

Defined Under Namespace

Classes: Options

Instance Method Summary collapse

Constructor Details

#initialize(xml, options) ⇒ Html

Initializes the Html extractor.

Parameters:

  • xml (Nokogiri::XML::Element)
  • options (Options)

Options Hash (options):

  • :selector (String)

    CSS selector used to find the element



35
36
37
# File 'lib/html2rss/selectors/extractors/html.rb', line 35

def initialize(xml, options)
  @element = Extractors.element(xml, options.selector)
end

Instance Method Details

#getString

Retrieves and returns the HTML content of the element.

Returns:

  • (String)

    The HTML content.



43
44
45
# File 'lib/html2rss/selectors/extractors/html.rb', line 43

def get
  @element.to_s
end