Class: Html2rss::AttributePostProcessors::HtmlTransformers::TransformUrlsToAbsoluteOnes
- Inherits:
-
Object
- Object
- Html2rss::AttributePostProcessors::HtmlTransformers::TransformUrlsToAbsoluteOnes
- Defined in:
- lib/html2rss/attribute_post_processors/html_transformers/transform_urls_to_absolute_ones.rb
Overview
Transformer that converts relative URLs to absolute URLs within specified HTML elements.
Constant Summary collapse
- URL_ELEMENTS_WITH_URL_ATTRIBUTE =
{ 'a' => :href, 'img' => :src }.freeze
Instance Method Summary collapse
-
#call(node_name:, node:, **_env) ⇒ Object
Transforms URLs to absolute ones.
-
#initialize(channel_url) ⇒ TransformUrlsToAbsoluteOnes
constructor
A new instance of TransformUrlsToAbsoluteOnes.
Constructor Details
#initialize(channel_url) ⇒ TransformUrlsToAbsoluteOnes
Returns a new instance of TransformUrlsToAbsoluteOnes.
11 12 13 |
# File 'lib/html2rss/attribute_post_processors/html_transformers/transform_urls_to_absolute_ones.rb', line 11 def initialize(channel_url) @channel_url = channel_url end |
Instance Method Details
#call(node_name:, node:, **_env) ⇒ Object
Transforms URLs to absolute ones.
17 18 19 20 21 22 23 |
# File 'lib/html2rss/attribute_post_processors/html_transformers/transform_urls_to_absolute_ones.rb', line 17 def call(node_name:, node:, **_env) return unless URL_ELEMENTS_WITH_URL_ATTRIBUTE.key?(node_name) url_attribute = URL_ELEMENTS_WITH_URL_ATTRIBUTE[node_name] url = node[url_attribute] node[url_attribute] = Html2rss::Utils.build_absolute_url_from_relative(url, @channel_url) end |