Sha256: f82632501fb79f3378f71e3f316f872604ec3ecdc4e62c01146fc1d9a9ec5be6

Contents?: true

Size: 1013 Bytes

Versions: 9

Compression:

Stored size: 1013 Bytes

Contents

module Html2rss
  module ItemExtractors
    ##
    # Returns the value of the +href+ attribute.
    # It always returns absolute URLs. If the extracted +href+ value is a
    # relative URL, it prepends the channel's URL.
    #
    # Imagine this +a+ HTML element with a +href+ attribute:
    #
    #     <a href="/posts/latest-findings">...</a>
    #
    # YAML usage example:
    #    channel:
    #      url: http://blog-without-a-feed.example.com
    #      ...
    #    selectors:
    #      link:
    #        selector: a
    #        extractor: href
    #
    # Would return:
    #    'http://blog-without-a-feed.example.com/posts/latest-findings'
    class Href
      def initialize(xml, options)
        @options = options
        element = ItemExtractors.element(xml, options)
        @href = element.attr('href').to_s
      end

      # @return [URI::HTTPS, URI::HTTP]
      def get
        Html2rss::Utils.build_absolute_url_from_relative(@href, @options['channel']['url'])
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
html2rss-0.8.1 lib/html2rss/item_extractors/href.rb
html2rss-0.8.0 lib/html2rss/item_extractors/href.rb
html2rss-0.7.0 lib/html2rss/item_extractors/href.rb
html2rss-0.6.0 lib/html2rss/item_extractors/href.rb
html2rss-0.5.2 lib/html2rss/item_extractors/href.rb
html2rss-0.5.1 lib/html2rss/item_extractors/href.rb
html2rss-0.5.0 lib/html2rss/item_extractors/href.rb
html2rss-0.4.1 lib/html2rss/item_extractors/href.rb
html2rss-0.4.0 lib/html2rss/item_extractors/href.rb