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 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/json/ld/html/rexml.rb, line 66 def ancestors @ancestors ||= parent ? parent.ancestors + [parent] : [] end
at_xpath(*args)
click to toggle source
# File lib/json/ld/html/rexml.rb, line 122 def at_xpath(*args) xpath(*args).first end
attribute_nodes()
click to toggle source
# File lib/json/ld/html/rexml.rb, line 91 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 32 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 110 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 61 def children NodeSetProxy.new(@node.children, self) end
display_path()
click to toggle source
# File lib/json/ld/html/rexml.rb, line 36 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 106 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 87 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 75 def inner_text coder = HTMLEntities.new ::REXML::XPath.match(@node,'.//text()').map { |e| coder.decode(e) }.join end
method_missing(method, *args)
click to toggle source
Proxy for everything else to @node
# File lib/json/ld/html/rexml.rb, line 128 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 102 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 53 def text_content? @node.children.all? {|c| c.is_a?(::REXML::Text)} end
to_s()
click to toggle source
# File lib/json/ld/html/rexml.rb, line 114 def to_s; @node.to_s; end
xpath(*args)
click to toggle source
# File lib/json/ld/html/rexml.rb, line 116 def xpath(*args) ::REXML::XPath.match(@node, *args).map do |n| NodeProxy.new(n, parent) end end