class RDF::RDFa::Reader::Nokogiri::NodeProxy

Proxy class to implement uniform element accessors

Attributes

node[R]
parent[R]

Public Class Methods

new(node, parent = nil) click to toggle source
# File lib/rdf/rdfa/reader/nokogiri.rb, line 21
def initialize(node, parent = nil)
  @node = node
  @parent = parent
end

Public Instance Methods

ancestors() click to toggle source

Ancestors of this element, in order

# File lib/rdf/rdfa/reader/nokogiri.rb, line 93
def ancestors
  @ancestors ||= parent ? parent.ancestors + [parent] : []
end
attribute_nodes() click to toggle source
Inner text of an element. Decode Entities

@return [String]

def inner_text

coder = HTMLEntities.new
coder.decode(@node.inner_text)

end

# File lib/rdf/rdfa/reader/nokogiri.rb, line 106
def attribute_nodes
  @attribute_nodes ||= NodeSetProxy.new(@node.attribute_nodes, self)
end
base() click to toggle source

Return xml:base on element, if defined

@return [String]

# File lib/rdf/rdfa/reader/nokogiri.rb, line 51
def base
  @node.attribute_with_ns("base", "http://www.w3.org/XML/1998/namespace") || @node.attribute('xml:base')
end
children() click to toggle source

Children of this node

@return [NodeSetProxy]

# File lib/rdf/rdfa/reader/nokogiri.rb, line 88
def children
  NodeSetProxy.new(@node.children, self)
end
display_path() click to toggle source
# File lib/rdf/rdfa/reader/nokogiri.rb, line 55
def display_path
  @display_path ||= begin
    path = []
    path << parent.display_path if parent
    path << @node.name
    case @node
    when ::Nokogiri::XML::Element then path.join("/")
    when ::Nokogiri::XML::Attr    then path.join("@")
    else path.join("?")
    end
  end
end
language() click to toggle source

Element language

From HTML5 3.2.3.3

If both the lang attribute in no namespace and the lang attribute in the XML namespace are set
on an element, user agents must use the lang attribute in the XML namespace, and the lang
attribute in no namespace must be ignored for the purposes of determining the element's
language.

@return [String]

# File lib/rdf/rdfa/reader/nokogiri.rb, line 36
def language
  case
  when @node.attribute_with_ns("lang", "http://www.w3.org/XML/1998/namespace")
    @node.attribute_with_ns("lang", "http://www.w3.org/XML/1998/namespace")
  when @node.attribute("xml:lang")
    @node.attribute("xml:lang").to_s
  when @node.attribute("lang")
    @node.attribute("lang").to_s
  end
end
method_missing(method, *args) click to toggle source

Proxy for everything else to @node

# File lib/rdf/rdfa/reader/nokogiri.rb, line 122
def method_missing(method, *args)
  @node.send(method, *args)
end
namespaces() click to toggle source

Retrieve XMLNS definitions for this element

@return [Hash{String => String}]

# File lib/rdf/rdfa/reader/nokogiri.rb, line 80
def namespaces
  @node.namespace_definitions.inject({}) {|memo, ns| memo[ns.prefix] = ns.href.to_s; memo }
end
text_content?() click to toggle source

Return true of all child elements are text

@return [Array<:text, :element, :attribute>]

# File lib/rdf/rdfa/reader/nokogiri.rb, line 72
def text_content?
  @node.children.all? {|c| c.text?}
end
xpath(*args) click to toggle source
# File lib/rdf/rdfa/reader/nokogiri.rb, line 110
def xpath(*args)
  @node.xpath(*args).map do |n|
    # Get node ancestors
    parent = n.ancestors.reverse.inject(nil) do |p,node|
      NodeProxy.new(node, p)
    end
    NodeProxy.new(n, parent)
  end
end