Sha256: 7dc5d49abd7410e9a530fcc1827cee151dc32ccb8bd15f7b3b4b6ab8e90077e7

Contents?: true

Size: 519 Bytes

Versions: 1

Compression:

Stored size: 519 Bytes

Contents

module Govspeak
  class LinkExtractor
    def initialize(document)
      @document = document
    end

    def call
      @links ||= extract_links
    end

  private

    def extract_links
      document_anchors.map { |link| link['href'] }
    end

    def document_anchors
      processed_govspeak.css('a:not([href^="mailto"])').css('a:not([href^="#"])')
    end

    def processed_govspeak
      doc = Nokogiri::HTML::Document.new
      doc.encoding = "UTF-8"

      doc.fragment(@document.to_html)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
govspeak-5.3.0 lib/govspeak/link_extractor.rb