class RDF::Microdata::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/microdata/reader/nokogiri.rb, line 21
def initialize(node, parent = nil)
  @node = node
  @parent = parent
end

Public Instance Methods

base() click to toggle source

Get any xml:base in effect for this element

# File lib/rdf/microdata/reader/nokogiri.rb, line 51
def base
  if @base.nil?
    @base = attributes['xml:base'] ||
    (parent && parent.element? && parent.base) ||
    false
  end

  @base == false ? nil : @base
end
children() click to toggle source

Children of this node

@return [NodeSetProxy]

# File lib/rdf/microdata/reader/nokogiri.rb, line 94
def children
  NodeSetProxy.new(@node.children, self)
end
display_path() click to toggle source
# File lib/rdf/microdata/reader/nokogiri.rb, line 61
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
elements() click to toggle source

Elements of this node

@return [NodeSetProxy]

# File lib/rdf/microdata/reader/nokogiri.rb, line 102
def elements
  NodeSetProxy.new(@node.elements, self)
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/microdata/reader/nokogiri.rb, line 36
def language
  language = case
  when @node.document.is_a?(::Nokogiri::XML::Document) && @node.attributes["xml:lang"]
    @node.attributes["xml:lang"].to_s
  when @node.document.is_a?(::Nokogiri::XML::Document) && @node.attributes["lang"]
    @node.attributes["lang"].to_s
  when @node.attribute("lang")
    @node.attribute("lang").to_s
  else
    parent && parent.element? && parent.language
  end
end
method_missing(method, *args) click to toggle source

Proxy for everything else to @node

# File lib/rdf/microdata/reader/nokogiri.rb, line 114
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/microdata/reader/nokogiri.rb, line 86
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/microdata/reader/nokogiri.rb, line 78
def text_content?
  @node.children.all? {|c| c.text?}
end
to_str() click to toggle source

Rational debug output

# File lib/rdf/microdata/reader/nokogiri.rb, line 108
def to_str
  @node.path
end