Class: RDF::Microdata::Reader::Nokogiri::NodeProxy
- Inherits:
-
Object
- Object
- RDF::Microdata::Reader::Nokogiri::NodeProxy
- Defined in:
- lib/rdf/microdata/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
-
#base ⇒ Object
Get any xml:base in effect for this element.
-
#children ⇒ NodeSetProxy
Children of this node.
- #display_path ⇒ Object
-
#elements ⇒ NodeSetProxy
Elements of this node.
-
#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.
-
#to_str ⇒ Object
Rational debug output.
Constructor Details
#initialize(node, parent = nil) ⇒ NodeProxy
Returns a new instance of NodeProxy.
21 22 23 24 |
# File 'lib/rdf/microdata/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
114 115 116 |
# File 'lib/rdf/microdata/reader/nokogiri.rb', line 114 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 'lib/rdf/microdata/reader/nokogiri.rb', line 18 def node @node end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
19 20 21 |
# File 'lib/rdf/microdata/reader/nokogiri.rb', line 19 def parent @parent end |
Instance Method Details
#base ⇒ Object
Get any xml:base in effect for this element
51 52 53 54 55 56 57 58 59 |
# File 'lib/rdf/microdata/reader/nokogiri.rb', line 51 def base if @base.nil? @base = attributes['xml:base'] || (parent && parent.element? && parent.base) || false end @base == false ? nil : @base end |
#children ⇒ NodeSetProxy
Children of this node
94 95 96 |
# File 'lib/rdf/microdata/reader/nokogiri.rb', line 94 def children NodeSetProxy.new(@node.children, self) end |
#display_path ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rdf/microdata/reader/nokogiri.rb', line 61 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 |
#elements ⇒ NodeSetProxy
Elements of this node
102 103 104 |
# File 'lib/rdf/microdata/reader/nokogiri.rb', line 102 def elements NodeSetProxy.new(@node.elements, self) 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 46 47 |
# File 'lib/rdf/microdata/reader/nokogiri.rb', line 36 def language language = case when @node.document.is_a?(::Nokogiri::XML::Document) && @node.attributes["xml:lang"] @node.attributes["xml:lang"].to_s when @node.document.is_a?(::Nokogiri::XML::Document) && @node.attributes["lang"] @node.attributes["lang"].to_s when @node.attribute("lang") @node.attribute("lang").to_s else parent && parent.element? && parent.language end end |
#namespaces ⇒ Hash{String => String}
Retrieve XMLNS definitions for this element
86 87 88 |
# File 'lib/rdf/microdata/reader/nokogiri.rb', line 86 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
78 79 80 |
# File 'lib/rdf/microdata/reader/nokogiri.rb', line 78 def text_content? @node.children.all? {|c| c.text?} end |
#to_str ⇒ Object
Rational debug output
108 109 110 |
# File 'lib/rdf/microdata/reader/nokogiri.rb', line 108 def to_str @node.path end |