Sha256: 9e857bbf130dde71ca8363d0d8537716700ef1e80a0fa023cf84a71f6aee1a73

Contents?: true

Size: 1.43 KB

Versions: 1

Compression:

Stored size: 1.43 KB

Contents

# frozen_string_literal: true

module ProxyFetcher
  class Document
    # Abstract HTML parser adapter class.
    # Handles document manipulations.
    class AbstractAdapter
      # @!attribute [r] events
      #   @return [Hash] A hash with events registered within a bus
      attr_reader :document

      # Initialize adapter
      #
      # @return [AbstractAdapter]
      #
      def initialize(document)
        @document = document
      end

      # You can override this method in your own adapter class
      #
      # @param selector [String]
      #   XPath selector
      #
      def xpath(selector)
        document.xpath(selector)
      end

      # You can override this method in your own adapter class
      #
      # @param selector [String]
      #   CSS selector
      #
      def css(selector)
        document.css(selector)
      end

      # Returns <code>Node</code> class that will handle HTML
      # nodes for particular adapter.
      #
      # @return [ProxyFetcher::Document::Node]
      #   node
      #
      def proxy_node
        self.class.const_get('Node')
      end

      # Installs adapter requirements.
      #
      # @raise [Exceptions::AdapterSetupError]
      #   adapter can't be install due to some error
      #
      def self.setup!(*args)
        install_requirements!(*args)
        self
      rescue LoadError => error
        raise Exceptions::AdapterSetupError.new(name, error.message)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
proxy_fetcher-0.10.1 lib/proxy_fetcher/document/adapters/abstract_adapter.rb