class JSON::LD::API::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/json/ld/html/rexml.rb, line 25
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/json/ld/html/rexml.rb, line 68
def ancestors
  @ancestors ||= parent ? parent.ancestors + [parent] : []
end
at_xpath(*args) click to toggle source
# File lib/json/ld/html/rexml.rb, line 126
def at_xpath(*args)
  xpath(*args).first
end
attribute_nodes() click to toggle source
# File lib/json/ld/html/rexml.rb, line 93
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/json/ld/html/rexml.rb, line 34
def base
  @node.attribute("base", RDF::XML.to_s) || @node.attribute('xml:base')
end
blank?() click to toggle source
# File lib/json/ld/html/rexml.rb, line 112
def blank?
  @node.is_a?(::REXML::Text) && @node.empty?
end
children() click to toggle source

Children of this node

@return [NodeSetProxy]

# File lib/json/ld/html/rexml.rb, line 63
def children
  NodeSetProxy.new(@node.children, self)
end
display_path() click to toggle source
# File lib/json/ld/html/rexml.rb, line 38
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/json/ld/html/rexml.rb, line 108
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/json/ld/html/rexml.rb, line 89
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/json/ld/html/rexml.rb, line 77
def inner_text
  coder = HTMLEntities.new
  ::REXML::XPath.match(@node, './/text()').map do |e|
    coder.decode(e)
  end.join
end
method_missing(method, *args) click to toggle source

Proxy for everything else to @node

# File lib/json/ld/html/rexml.rb, line 132
def method_missing(method, *args)
  @node.send(method, *args)
end
text?() click to toggle source

Node type accessors

@return [Boolean]

# File lib/json/ld/html/rexml.rb, line 104
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/json/ld/html/rexml.rb, line 55
def text_content?
  @node.children.all?(::REXML::Text)
end
to_s() click to toggle source
# File lib/json/ld/html/rexml.rb, line 116
def to_s
  @node.to_s
end
xpath(*args) click to toggle source
# File lib/json/ld/html/rexml.rb, line 120
def xpath(*args)
  ::REXML::XPath.match(@node, *args).map do |n|
    NodeProxy.new(n, parent)
  end
end