Class: RDF::RDFa::Reader::REXML::NodeProxy
- Inherits:
-
Object
- Object
- RDF::RDFa::Reader::REXML::NodeProxy
- Defined in:
- lib/rdf/rdfa/reader/rexml.rb
Overview
Proxy class to implement uniform element accessors
Instance Attribute Summary (collapse)
-
- (Object) node
readonly
Returns the value of attribute node.
-
- (Object) parent
readonly
Returns the value of attribute parent.
Instance Method Summary (collapse)
-
- (String) base
Return xml:base on element, if defined.
-
- (NodeSetProxy) children
Children of this node.
- - (Object) display_path
-
- (Boolean) element?
Node type accessors.
-
- (NodeProxy) initialize(node, parent = nil)
constructor
A new instance of NodeProxy.
-
- (String) inner_html
Inner text of an element.
-
- (String) inner_text
Inner text of an element.
-
- (String) language
Element language.
-
- (Object) method_missing(method, *args)
Proxy for everything else to @node.
-
- (Hash{String => String}) namespaces
Retrieve XMLNS definitions for this element.
-
- (Array<:text, :element, :attribute>) text_content?
Return true of all child elements are text.
Constructor Details
- (NodeProxy) initialize(node, parent = nil)
A new instance of NodeProxy
23 24 25 26 |
# File 'lib/rdf/rdfa/reader/rexml.rb', line 23 def initialize(node, parent = nil) @node = node @parent = parent end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(method, *args)
Proxy for everything else to @node
128 129 130 |
# File 'lib/rdf/rdfa/reader/rexml.rb', line 128 def method_missing(method, *args) @node.send(method, *args) end |
Instance Attribute Details
- (Object) node (readonly)
Returns the value of attribute node
20 21 22 |
# File 'lib/rdf/rdfa/reader/rexml.rb', line 20 def node @node end |
- (Object) parent (readonly)
Returns the value of attribute parent
21 22 23 |
# File 'lib/rdf/rdfa/reader/rexml.rb', line 21 def parent @parent end |
Instance Method Details
- (String) base
Return xml:base on element, if defined
51 52 53 |
# File 'lib/rdf/rdfa/reader/rexml.rb', line 51 def base @node.attribute("base", RDF::XML.to_s) end |
- (NodeSetProxy) children
Children of this node
93 94 95 |
# File 'lib/rdf/rdfa/reader/rexml.rb', line 93 def children NodeSetProxy.new(@node.children, self) end |
- (Object) display_path
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/rdf/rdfa/reader/rexml.rb', line 55 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 |
- (Boolean) element?
Node type accessors
122 123 124 |
# File 'lib/rdf/rdfa/reader/rexml.rb', line 122 def element? @node.is_a?(::REXML::Element) end |
- (String) inner_html
Inner text of an element
114 115 116 |
# File 'lib/rdf/rdfa/reader/rexml.rb', line 114 def inner_html @node.children.map(&:to_s).join end |
- (String) inner_text
Inner text of an element
102 103 104 105 106 107 |
# File 'lib/rdf/rdfa/reader/rexml.rb', line 102 def inner_text coder = HTMLEntities.new ::REXML::XPath.match(@node,'.//text()').map { |e| coder.decode(e) }.join end |
- (String) language
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.
38 39 40 41 42 43 44 45 |
# File 'lib/rdf/rdfa/reader/rexml.rb', line 38 def language language = case when @node.attribute("lang", RDF::XML.to_s) @node.attribute("lang", RDF::XML.to_s) when @node.attribute("lang") @node.attribute("lang").to_s end end |
- (Hash{String => String}) namespaces
Retrieve XMLNS definitions for this element
80 81 82 83 84 85 86 87 |
# File 'lib/rdf/rdfa/reader/rexml.rb', line 80 def namespaces ns_decls = {} @node.attributes.each do |name, attr| next unless name =~ /^xmlns(?:\:(.+))?/ ns_decls[$1] = attr end ns_decls end |
- (Array<:text, :element, :attribute>) text_content?
Return true of all child elements are text
72 73 74 |
# File 'lib/rdf/rdfa/reader/rexml.rb', line 72 def text_content? @node.children.all? {|c| c.is_a?(::REXML::Text)} end |