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

Constant Summary collapse

DESCRIPTION =

JSON Schema description exported via schema_doc.

'Return the outer HTML of the selected element. ' \
'Sanitize during post-processing (e.g. `sanitize_html`).'
EXAMPLES =

Example extractor name values for JSON Schema examples.

[
  'html'
].freeze

Class Method Summary collapse

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



47
48
49
# File 'lib/html2rss/selectors/extractors/html.rb', line 47

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

Class Method Details

.schema_docHash{Symbol => Object}

Returns JSON Schema fragment for this extractor name.

Returns:

  • (Hash{Symbol => Object})

    JSON Schema fragment for this extractor name



39
# File 'lib/html2rss/selectors/extractors/html.rb', line 39

def self.schema_doc = SchemaDoc.for_extractor(name: :html, klass: self)

Instance Method Details

#getString

Retrieves and returns the HTML content of the element.

Returns:

  • (String)

    The HTML content.



55
56
57
# File 'lib/html2rss/selectors/extractors/html.rb', line 55

def get
  @element.to_s
end