Sha256: ebf2b5686df3e62defd4e87e19bc31377ecf0b2432eedb6dd97f450e602b7dee

Contents?: true

Size: 1.21 KB

Versions: 10

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

module ProxyFetcher
  class Document
    # HTML parser adapter that uses Nokogiri as a backend.
    class NokogiriAdapter < AbstractAdapter
      # Requires Nokogiri gem to the application.
      def self.install_requirements!
        require 'nokogiri'
      end

      # Parses raw HTML content with specific gem.
      #
      # @param data [String]
      #   HTML content
      #
      # @return [ProxyFetcher::Document::NokogiriAdapter]
      #   Object with parsed document
      #
      def self.parse(data)
        new(::Nokogiri::HTML(data))
      end

      # Nokogiri DOM node
      class Node < ProxyFetcher::Document::Node
        # Returns HTML node attribute value.
        #
        # @return [String] attribute value
        #
        def attr(*args)
          clear(node.attr(*args))
        end

        # Returns HTML node inner text value clean from
        # whitespaces, tabs, etc.
        #
        # @return [String] node inner text
        #
        def content
          clear(node.content)
        end

        # Returns node inner HTML.
        #
        # @return [String] inner HTML
        #
        def html
          node.inner_html
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
proxy_fetcher-0.10.2 lib/proxy_fetcher/document/adapters/nokogiri_adapter.rb
proxy_fetcher-0.10.1 lib/proxy_fetcher/document/adapters/nokogiri_adapter.rb
proxy_fetcher-0.10.0 lib/proxy_fetcher/document/adapters/nokogiri_adapter.rb
proxy_fetcher-0.9.0 lib/proxy_fetcher/document/adapters/nokogiri_adapter.rb
proxy_fetcher-0.8.0 lib/proxy_fetcher/document/adapters/nokogiri_adapter.rb
proxy_fetcher-0.7.1 lib/proxy_fetcher/document/adapters/nokogiri_adapter.rb
proxy_fetcher-0.7.0 lib/proxy_fetcher/document/adapters/nokogiri_adapter.rb
proxy_fetcher-0.6.5 lib/proxy_fetcher/document/adapters/nokogiri_adapter.rb
proxy_fetcher-0.6.4 lib/proxy_fetcher/document/adapters/nokogiri_adapter.rb
proxy_fetcher-0.6.3 lib/proxy_fetcher/document/adapters/nokogiri_adapter.rb