Class: JSON::LD::API::Nokogiri::NodeProxy
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/json-ld-f1de87658826/lib/json/ld/html/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.
-
#method_missing(method, *args) ⇒ Object
Proxy for everything else to @node.
-
#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.
23 24 25 26 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/json-ld-f1de87658826/lib/json/ld/html/nokogiri.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
95 96 97 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/json-ld-f1de87658826/lib/json/ld/html/nokogiri.rb', line 95 def method_missing(method, *args) @node.send(method, *args) end |
Instance Attribute Details
#node ⇒ Object (readonly)
Returns the value of attribute node.
21 22 23 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/json-ld-f1de87658826/lib/json/ld/html/nokogiri.rb', line 21 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/json-ld-f1de87658826/lib/json/ld/html/nokogiri.rb', line 21 def parent @parent end |
Instance Method Details
#ancestors ⇒ Object
Ancestors of this element, in order
66 67 68 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/json-ld-f1de87658826/lib/json/ld/html/nokogiri.rb', line 66 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
79 80 81 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/json-ld-f1de87658826/lib/json/ld/html/nokogiri.rb', line 79 def attribute_nodes @attribute_nodes ||= NodeSetProxy.new(@node.attribute_nodes, self) end |
#base ⇒ String
Return xml:base on element, if defined
32 33 34 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/json-ld-f1de87658826/lib/json/ld/html/nokogiri.rb', line 32 def base @node.attribute_with_ns("base", RDF::XML.to_s) || @node.attribute('xml:base') end |
#children ⇒ NodeSetProxy
Children of this node
61 62 63 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/json-ld-f1de87658826/lib/json/ld/html/nokogiri.rb', line 61 def children NodeSetProxy.new(@node.children, self) end |
#display_path ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/json-ld-f1de87658826/lib/json/ld/html/nokogiri.rb', line 36 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 |
#text_content? ⇒ Array<:text, :element, :attribute>
Return true of all child elements are text
53 54 55 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/json-ld-f1de87658826/lib/json/ld/html/nokogiri.rb', line 53 def text_content? @node.children.all?(&:text?) end |
#xpath(*args) ⇒ Object
83 84 85 86 87 88 89 90 91 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/json-ld-f1de87658826/lib/json/ld/html/nokogiri.rb', line 83 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 |