Class: RDF::RDFa::Reader::Nokogiri::NodeProxy
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/reader/nokogiri.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.
-
#attribute_nodes ⇒ String
Inner text of an element.
-
#base ⇒ String
Return xml:base on element, if defined.
-
#children ⇒ NodeSetProxy
Children of this node.
- #display_path ⇒ Object
-
#initialize(node, parent = nil) ⇒ NodeProxy
constructor
A new instance of NodeProxy.
-
#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_content? ⇒ Array<:text, :element, :attribute>
Return true of all child elements are text.
- #xpath(*args) ⇒ Object
Constructor Details
#initialize(node, parent = nil) ⇒ NodeProxy
Returns a new instance of NodeProxy.
21 22 23 24 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/reader/nokogiri.rb', line 21 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
122 123 124 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/reader/nokogiri.rb', line 122 def method_missing(method, *args) @node.send(method, *args) end |
Instance Attribute Details
#node ⇒ Object (readonly)
Returns the value of attribute node.
18 19 20 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/reader/nokogiri.rb', line 18 def node @node end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
19 20 21 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/reader/nokogiri.rb', line 19 def parent @parent end |
Instance Method Details
#ancestors ⇒ Object
Ancestors of this element, in order
93 94 95 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/reader/nokogiri.rb', line 93 def ancestors @ancestors ||= parent ? parent.ancestors + [parent] : [] end |
#attribute_nodes ⇒ String
Inner text of an element. Decode Entities
def inner_text coder = HTMLEntities.new coder.decode(@node.inner_text) end
106 107 108 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/reader/nokogiri.rb', line 106 def attribute_nodes @attribute_nodes ||= NodeSetProxy.new(@node.attribute_nodes, self) end |
#base ⇒ String
Return xml:base on element, if defined
51 52 53 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/reader/nokogiri.rb', line 51 def base @node.attribute_with_ns("base", "http://www.w3.org/XML/1998/namespace") || @node.attribute('xml:base') end |
#children ⇒ NodeSetProxy
Children of this node
88 89 90 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/reader/nokogiri.rb', line 88 def children NodeSetProxy.new(@node.children, self) end |
#display_path ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/reader/nokogiri.rb', line 55 def display_path @display_path ||= begin path = [] path << parent.display_path if parent path << @node.name case @node when ::Nokogiri::XML::Element then path.join("/") when ::Nokogiri::XML::Attr then path.join("@") else path.join("?") end end 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.
36 37 38 39 40 41 42 43 44 45 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/reader/nokogiri.rb', line 36 def language case when @node.attribute_with_ns("lang", "http://www.w3.org/XML/1998/namespace") @node.attribute_with_ns("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
80 81 82 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/reader/nokogiri.rb', line 80 def namespaces @node.namespace_definitions.inject({}) {|memo, ns| memo[ns.prefix] = ns.href.to_s; memo } end |
#text_content? ⇒ Array<:text, :element, :attribute>
Return true of all child elements are text
72 73 74 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/reader/nokogiri.rb', line 72 def text_content? @node.children.all? {|c| c.text?} end |
#xpath(*args) ⇒ Object
110 111 112 113 114 115 116 117 118 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-rdfa-ea6265716853/lib/rdf/rdfa/reader/nokogiri.rb', line 110 def xpath(*args) @node.xpath(*args).map do |n| # Get node ancestors parent = n.ancestors.reverse.inject(nil) do |p,node| NodeProxy.new(node, p) end NodeProxy.new(n, parent) end end |