class RDF::RDFa::Reader::REXML::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/rexml.rb, line 23
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/rexml.rb, line 100
def ancestors
  @ancestors ||= parent ? parent.ancestors + [parent] : []
end
at_xpath(*args) click to toggle source
# File lib/rdf/rdfa/reader/rexml.rb, line 156
def at_xpath(*args)
  xpath(*args).first
end
attribute_nodes() click to toggle source
# File lib/rdf/rdfa/reader/rexml.rb, line 125
def attribute_nodes
  attrs = @node.attributes.dup.keep_if do |name, attr|
    !name.start_with?('xmlns')
  end
  @attribute_nodes ||= (attrs.empty? ? attrs : NodeSetProxy.new(attrs, self))
end
base() click to toggle source

Return xml:base on element, if defined

@return [String]

# File lib/rdf/rdfa/reader/rexml.rb, line 53
def base
  @node.attribute("base", "http://www.w3.org/XML/1998/namespace") || @node.attribute('xml:base')
end
blank?() click to toggle source
# File lib/rdf/rdfa/reader/rexml.rb, line 144
def blank?
  @node.is_a?(::REXML::Text) && @node.empty?
end
children() click to toggle source

Children of this node

@return [NodeSetProxy]

# File lib/rdf/rdfa/reader/rexml.rb, line 95
def children
  NodeSetProxy.new(@node.children, self)
end
css(path) click to toggle source

Simple case for <script>

# File lib/rdf/rdfa/reader/rexml.rb, line 161
def css(path)
  xpath("//script[@type]")
end
display_path() click to toggle source
# File lib/rdf/rdfa/reader/rexml.rb, line 57
def display_path
  @display_path ||= begin
    path = []
    path << parent.display_path if parent
    path << @node.name
    case @node
    when ::REXML::Element   then path.join("/")
    when ::REXML::Attribute then path.join("@")
    else path.join("?")
    end
  end
end
element?() click to toggle source
# File lib/rdf/rdfa/reader/rexml.rb, line 140
def element?
  @node.is_a?(::REXML::Element)
end
inner_html() click to toggle source

Inner text of an element

@see apidock.com/ruby/REXML/Element/get_text#743-Get-all-inner-texts @return [String]

# File lib/rdf/rdfa/reader/rexml.rb, line 121
def inner_html
  @node.children.map(&:to_s).join
end
inner_text() click to toggle source

Inner text of an element

@see apidock.com/ruby/REXML/Element/get_text#743-Get-all-inner-texts @return [String]

# File lib/rdf/rdfa/reader/rexml.rb, line 109
def inner_text
  coder = HTMLEntities.new
  ::REXML::XPath.match(@node,'.//text()').map { |e|
    coder.decode(e)
  }.join
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/rexml.rb, line 38
def language
  case
  when @node.attribute("lang", "http://www.w3.org/XML/1998/namespace")
    @node.attribute("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/rexml.rb, line 167
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/rexml.rb, line 82
def namespaces
  ns_decls = {}
  @node.attributes.each do |name, attr|
    next unless name =~ /^xmlns(?:\:(.+))?/
    ns_decls[$1] = attr
  end
  ns_decls
end
text?() click to toggle source

Node type accessors

@return [Boolean]

# File lib/rdf/rdfa/reader/rexml.rb, line 136
def text?
  @node.is_a?(::REXML::Text)
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/rexml.rb, line 74
def text_content?
  @node.children.all? {|c| c.is_a?(::REXML::Text)}
end
to_s() click to toggle source
# File lib/rdf/rdfa/reader/rexml.rb, line 148
def to_s; @node.to_s; end
xpath(*args) click to toggle source
# File lib/rdf/rdfa/reader/rexml.rb, line 150
def xpath(*args)
  ::REXML::XPath.match(@node, *args).map do |n|
    NodeProxy.new(n, parent)
  end
end