Sha256: 45541315a0f747ff37498147d19a61ec943b81962d9fb0b4ba9e7c4831ac3a1d

Contents?: true

Size: 991 Bytes

Versions: 2

Compression:

Stored size: 991 Bytes

Contents

# frozen_string_literal: true

module Html2rss
  module AttributePostProcessors
    ##
    # 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'
    class ParseUri
      ##
      # @param value [String]
      # @param context [Item::Context]
      def initialize(value, context)
        @value = value
        @config_url = context.config.url
      end

      ##
      # @return [String]
      def get
        Html2rss::Utils.build_absolute_url_from_relative(
          Html2rss::Utils.sanitize_url(@value),
          @config_url
        ).to_s
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
html2rss-0.11.0 lib/html2rss/attribute_post_processors/parse_uri.rb
html2rss-0.10.0 lib/html2rss/attribute_post_processors/parse_uri.rb