class ProxyFetcher::Document

HTML document abstraction class. Used to work with different HTML parser adapters such as Nokogiri, Oga or a custom one. Stores <i>backend</i< that will handle all the DOM manipulation logic.

Attributes

backend[R]

@!attribute [r] backend

@return [Object] Backend object that handles DOM processing

Public Class Methods

new(backend) click to toggle source

Initialize abstract ProxyFetcher HTML Document

@return [Document]

# File lib/proxy_fetcher/document.rb, line 27
def initialize(backend)
  @backend = backend
end
parse(data) click to toggle source

Parses raw HTML data to abstract ProxyFetcher document.

@param data [String] HTML

@return [ProxyFetcher::Document]

ProxyFetcher document model
# File lib/proxy_fetcher/document.rb, line 19
def self.parse(data)
  new(ProxyFetcher.config.adapter_class.parse(data))
end

Public Instance Methods

xpath(*args) click to toggle source

Searches elements by XPath selector.

@return [Array<ProxyFetcher::Document::Node>]

collection of nodes
# File lib/proxy_fetcher/document.rb, line 36
def xpath(*args)
  backend.xpath(*args).map { |node| backend.proxy_node.new(node) }
end