Class: RDF::RDFa::Reader::REXML::NodeProxy
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/reader/rexml.rb
Overview
Proxy class to implement uniform element accessors
Instance Attribute Summary collapse
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
-
#ancestors ⇒ Object
Ancestors of this element, in order.
- #at_xpath(*args) ⇒ Object
- #attribute_nodes ⇒ Object
-
#base ⇒ String
Return xml:base on element, if defined.
- #blank? ⇒ Boolean
-
#children ⇒ NodeSetProxy
Children of this node.
-
#css(path) ⇒ Object
Simple case for <script>.
- #display_path ⇒ Object
- #element? ⇒ Boolean
-
#initialize(node, parent = nil) ⇒ NodeProxy
constructor
A new instance of NodeProxy.
-
#inner_html ⇒ String
Inner text of an element.
-
#inner_text ⇒ String
Inner text of an element.
-
#language ⇒ String
Element language.
-
#method_missing(method, *args) ⇒ Object
Proxy for everything else to @node.
-
#namespaces ⇒ Hash{String => String}
Retrieve XMLNS definitions for this element.
-
#text? ⇒ Boolean
Node type accessors.
-
#text_content? ⇒ Array<:text, :element, :attribute>
Return true of all child elements are text.
- #to_s ⇒ Object
- #xpath(*args) ⇒ Object
Constructor Details
#initialize(node, parent = nil) ⇒ NodeProxy
Returns a new instance of NodeProxy.
23 24 25 26 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/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
#method_missing(method, *args) ⇒ Object
Proxy for everything else to @node
167 168 169 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/reader/rexml.rb', line 167 def method_missing(method, *args) @node.send(method, *args) end |
Instance Attribute Details
#node ⇒ Object (readonly)
Returns the value of attribute node.
20 21 22 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/reader/rexml.rb', line 20 def node @node end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
21 22 23 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/reader/rexml.rb', line 21 def parent @parent end |
Instance Method Details
#ancestors ⇒ Object
Ancestors of this element, in order
100 101 102 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/reader/rexml.rb', line 100 def ancestors @ancestors ||= parent ? parent.ancestors + [parent] : [] end |
#at_xpath(*args) ⇒ Object
156 157 158 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/reader/rexml.rb', line 156 def at_xpath(*args) xpath(*args).first end |
#attribute_nodes ⇒ Object
125 126 127 128 129 130 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/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 ⇒ String
Return xml:base on element, if defined
53 54 55 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/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? ⇒ Boolean
144 145 146 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/reader/rexml.rb', line 144 def blank? @node.is_a?(::REXML::Text) && @node.empty? end |
#children ⇒ NodeSetProxy
Children of this node
95 96 97 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/reader/rexml.rb', line 95 def children NodeSetProxy.new(@node.children, self) end |
#css(path) ⇒ Object
Simple case for <script>
161 162 163 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/reader/rexml.rb', line 161 def css(path) xpath("//script[@type]") end |
#display_path ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/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? ⇒ Boolean
140 141 142 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/reader/rexml.rb', line 140 def element? @node.is_a?(::REXML::Element) end |
#inner_html ⇒ String
Inner text of an element
121 122 123 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/reader/rexml.rb', line 121 def inner_html @node.children.map(&:to_s).join end |
#inner_text ⇒ String
Inner text of an element
109 110 111 112 113 114 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/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 ⇒ String
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 46 47 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/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 |
#namespaces ⇒ Hash{String => String}
Retrieve XMLNS definitions for this element
82 83 84 85 86 87 88 89 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/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? ⇒ Boolean
Node type accessors
136 137 138 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/reader/rexml.rb', line 136 def text? @node.is_a?(::REXML::Text) end |
#text_content? ⇒ Array<:text, :element, :attribute>
Return true of all child elements are text
74 75 76 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/reader/rexml.rb', line 74 def text_content? @node.children.all? {|c| c.is_a?(::REXML::Text)} end |
#to_s ⇒ Object
148 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/reader/rexml.rb', line 148 def to_s; @node.to_s; end |