module HtmlEntry::Page

Page module

Public Class Methods

fetch_node(document, instruction) click to toggle source

Get node by XPath or CSS selector

@param [Nokogiri::HTML::Document] document @param [Hash] instruction @return [Nokogiri::XML::Element]

# File lib/html_entry/page.rb, line 13
def fetch_node(document, instruction)
  nodes = fetch_nodes(document, instruction)
  nodes.first if nodes
end
fetch_nodes(document, instruction) click to toggle source

Get nodes by XPath or CSS selector

@param [Nokogiri::HTML::Document|Nokogiri::XML::Element] document @param [Hash] instruction @return [Nokogiri::XML::NodeSet]

# File lib/html_entry/page.rb, line 25
def fetch_nodes(document, instruction)
  unless document.instance_of?(Nokogiri::HTML::Document) || document.instance_of?(Nokogiri::XML::Element)
    raise '"document" must be an instance of Nokogiri::HTML::Document.'
  end
  if instruction[:selector]
    document.css(instruction[:selector])
  elsif instruction[:css]
    document.css(instruction[:css])
  elsif instruction[:xpath]
    if defined? document.xpath
      document.xpath(instruction[:xpath])
    else
      raise 'Cannot use this document.'
    end
  end
end

Private Instance Methods

fetch_node(document, instruction) click to toggle source

Get node by XPath or CSS selector

@param [Nokogiri::HTML::Document] document @param [Hash] instruction @return [Nokogiri::XML::Element]

# File lib/html_entry/page.rb, line 13
def fetch_node(document, instruction)
  nodes = fetch_nodes(document, instruction)
  nodes.first if nodes
end
fetch_nodes(document, instruction) click to toggle source

Get nodes by XPath or CSS selector

@param [Nokogiri::HTML::Document|Nokogiri::XML::Element] document @param [Hash] instruction @return [Nokogiri::XML::NodeSet]

# File lib/html_entry/page.rb, line 25
def fetch_nodes(document, instruction)
  unless document.instance_of?(Nokogiri::HTML::Document) || document.instance_of?(Nokogiri::XML::Element)
    raise '"document" must be an instance of Nokogiri::HTML::Document.'
  end
  if instruction[:selector]
    document.css(instruction[:selector])
  elsif instruction[:css]
    document.css(instruction[:css])
  elsif instruction[:xpath]
    if defined? document.xpath
      document.xpath(instruction[:xpath])
    else
      raise 'Cannot use this document.'
    end
  end
end