Class: RDF::RDFa::Reader::Nokogiri::NodeProxy
- Inherits:
-
Object
- Object
- RDF::RDFa::Reader::Nokogiri::NodeProxy
- Defined in:
- lib/rdf/rdfa/reader/nokogiri.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
-
- (NodeProxy) initialize(node, parent = nil)
constructor
A new instance of NodeProxy.
-
- (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
21 22 23 24 |
# File '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
- (Object) method_missing(method, *args)
Proxy for everything else to @node
96 97 98 |
# File 'lib/rdf/rdfa/reader/nokogiri.rb', line 96 def method_missing(method, *args) @node.send(method, *args) end |
Instance Attribute Details
- (Object) node (readonly)
Returns the value of attribute node
18 19 20 |
# File 'lib/rdf/rdfa/reader/nokogiri.rb', line 18 def node @node end |
- (Object) parent (readonly)
Returns the value of attribute parent
19 20 21 |
# File 'lib/rdf/rdfa/reader/nokogiri.rb', line 19 def parent @parent end |
Instance Method Details
- (String) base
Return xml:base on element, if defined
53 54 55 |
# File 'lib/rdf/rdfa/reader/nokogiri.rb', line 53 def base @node.attribute_with_ns("base", RDF::XML.to_s) end |
- (NodeSetProxy) children
Children of this node
90 91 92 |
# File 'lib/rdf/rdfa/reader/nokogiri.rb', line 90 def children NodeSetProxy.new(@node.children, self) end |
- (Object) display_path
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rdf/rdfa/reader/nokogiri.rb', line 57 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 |
- (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.
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rdf/rdfa/reader/nokogiri.rb', line 36 def language language = case when @node.document.is_a?(::Nokogiri::HTML::Document) && @node.attributes["xml:lang"] @node.attributes["xml:lang"].to_s when @node.document.is_a?(::Nokogiri::HTML::Document) && @node.attributes["lang"] @node.attributes["lang"].to_s when @node.attribute_with_ns("lang", RDF::XML.to_s) @node.attribute_with_ns("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
82 83 84 |
# File 'lib/rdf/rdfa/reader/nokogiri.rb', line 82 def namespaces @node.namespace_definitions.inject({}) {|memo, ns| memo[ns.prefix] = ns.href.to_s; memo } end |
- (Array<:text, :element, :attribute>) text_content?
Return true of all child elements are text
74 75 76 |
# File 'lib/rdf/rdfa/reader/nokogiri.rb', line 74 def text_content? @node.children.all? {|c| c.text?} end |