class ProxyFetcher::Document::Node
Abstract class for storing HTML elements that was parsed by one of the ProxyFetcher::Document
adapters class.
Attributes
@!attribute [r] node
@return [Object] original DOM node, parsed by adapter backend
Public Class Methods
Initialize new HTML node
@return [Node]
# File lib/proxy_fetcher/document/node.rb, line 16 def initialize(node) @node = node end
Public Instance Methods
Searches exact HTML element by CSS. Returns only one element.
@return [ProxyFetcher::Document::Node]
node
# File lib/proxy_fetcher/document/node.rb, line 44 def at_css(*args) self.class.new(node.at_css(*args)) end
Searches exact HTML element by XPath. Returns only one element.
@return [ProxyFetcher::Document::Node]
node
# File lib/proxy_fetcher/document/node.rb, line 35 def at_xpath(*args) self.class.new(node.at_xpath(*args)) end
Returns HTML node content.
Abstract method, must be implemented for specific adapter class.
# File lib/proxy_fetcher/document/node.rb, line 61 def content raise "`#{__method__}` must be implemented for specific adapter class!" end
Returns clean content (text) for the specific element.
@return [String]
HTML node content
# File lib/proxy_fetcher/document/node.rb, line 53 def content_at(*args) clear(find(*args).content) end
Searches for node in children using some selector (CSS or XPath).
@param selector [String] selector (CSS or XPath)
@return [Node] child node
# File lib/proxy_fetcher/document/node.rb, line 26 def find(selector, method = :at_xpath) self.class.new(node.public_send(method, selector)) end
Returns HTML node inner HTML.
Abstract method, must be implemented for specific adapter class.
# File lib/proxy_fetcher/document/node.rb, line 69 def html raise "`#{__method__}` must be implemented for specific adapter class!" end
Protected Instance Methods
Removes whitespaces, tabulation and other “garbage” for the text.
@param text [String]
text to clear
@return [String]
clean text
# File lib/proxy_fetcher/document/node.rb, line 83 def clear(text) return "" if text.nil? || text.empty? text.strip.gsub(/\t/i, "") end