Class: Html2rss::Selectors::PostProcessors::ParseUri

Inherits:
Base
  • Object
show all
Defined in:
lib/html2rss/selectors/post_processors/parse_uri.rb

Overview

Returns the normalized URL as a String. If the URL is relative, it resolves it against the channel URL.

Imagine this HTML structure:

http://why-not-use-a-link.uh 

YAML usage example:

selectors:
 link:
   selector: span
   extractor: text
   post_process:
     name: parse_uri

Would return:

'http://why-not-use-a-link.uh'

Constant Summary collapse

DESCRIPTION =

JSON Schema description exported via schema_doc.

'Normalize a URL string; resolve relative URLs against the channel URL.'
EXAMPLES =

Example post-process objects for JSON Schema examples.

[
  { 'name' => 'parse_uri' }
].freeze

Instance Attribute Summary

Attributes inherited from Base

#context, #value

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

assert_type, expect_options, #initialize

Constructor Details

This class inherits a constructor from Html2rss::Selectors::PostProcessors::Base

Class Method Details

.schema_docHash{Symbol => Object}

Returns JSON Schema fragment for this post-processor.

Returns:

  • (Hash{Symbol => Object})

    JSON Schema fragment for this post-processor



35
# File 'lib/html2rss/selectors/post_processors/parse_uri.rb', line 35

def self.schema_doc = SchemaDoc.for_post_processor(name: :parse_uri, klass: self)

.validate_args!(value, _context) ⇒ void

This method returns an undefined value.

Parameters:

  • value (String)

    extracted selector value

  • _context (Selectors::Context)

    post-processor context

Raises:

  • (ArgumentError)


40
41
42
# File 'lib/html2rss/selectors/post_processors/parse_uri.rb', line 40

def self.validate_args!(value, _context)
  raise ArgumentError, 'The `value` option is missing or empty.' if value.to_s.empty?
end

Instance Method Details

#getString

Returns:

  • (String)


46
47
48
49
50
# File 'lib/html2rss/selectors/post_processors/parse_uri.rb', line 46

def get
  config_url = context.dig(:config, :channel, :url)

  Url.from_relative(value, config_url).to_s
end