Class: Html2rss::AttributePostProcessors::ParseUri

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

Overview

Returns the URI as String. If the URL is relative, it builds an absolute one with the channel’s URL as base.

Imagine this HTML structure:

<span>http://why-not-use-a-link.uh </span>

YAML usage example:

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

Would return:

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

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::AttributePostProcessors::Base

Class Method Details

.validate_args!(value, context) ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
28
29
30
31
32
# File 'lib/html2rss/attribute_post_processors/parse_uri.rb', line 25

def self.validate_args!(value, context)
  url_types = [String, URI::HTTP, Addressable::URI].freeze

  assert_type(value, url_types, :value, context:)
  assert_type(context.config.url, url_types, :url, context:)

  raise ArgumentError, 'The `value` option is missing or empty.' if value.to_s.empty?
end

Instance Method Details

#getString

Returns:

  • (String)


36
37
38
39
40
41
42
43
# File 'lib/html2rss/attribute_post_processors/parse_uri.rb', line 36

def get
  config_url = context.config.url

  Html2rss::Utils.build_absolute_url_from_relative(
    Html2rss::Utils.sanitize_url(value),
    config_url
  ).to_s
end