Class: RDF::Microdata::Reader::Nokogiri::NodeProxy

Inherits:
Object
  • Object
show all
Defined in:
vendor/bundler/ruby/2.5.0/bundler/gems/rdf-microdata-2d8dbca83eec/lib/rdf/microdata/reader/nokogiri.rb

Overview

Proxy class to implement uniform element accessors

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, parent = nil) ⇒ NodeProxy

Returns a new instance of NodeProxy



21
22
23
24
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-microdata-2d8dbca83eec/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 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-microdata-2d8dbca83eec/lib/rdf/microdata/reader/nokogiri.rb', line 114

def method_missing(method, *args)
  @node.send(method, *args)
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node



18
19
20
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-microdata-2d8dbca83eec/lib/rdf/microdata/reader/nokogiri.rb', line 18

def node
  @node
end

#parentObject (readonly)

Returns the value of attribute parent



19
20
21
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-microdata-2d8dbca83eec/lib/rdf/microdata/reader/nokogiri.rb', line 19

def parent
  @parent
end

Instance Method Details

#baseObject

Get any xml:base in effect for this element



51
52
53
54
55
56
57
58
59
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-microdata-2d8dbca83eec/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

#childrenNodeSetProxy

Children of this node

Returns:



94
95
96
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-microdata-2d8dbca83eec/lib/rdf/microdata/reader/nokogiri.rb', line 94

def children
  NodeSetProxy.new(@node.children, self)
end

#display_pathObject



61
62
63
64
65
66
67
68
69
70
71
72
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-microdata-2d8dbca83eec/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

#elementsNodeSetProxy

Elements of this node

Returns:



102
103
104
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-microdata-2d8dbca83eec/lib/rdf/microdata/reader/nokogiri.rb', line 102

def elements
  NodeSetProxy.new(@node.elements, self)
end

#languageString

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.

Returns:



36
37
38
39
40
41
42
43
44
45
46
47
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-microdata-2d8dbca83eec/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

#namespacesHash{String => String}

Retrieve XMLNS definitions for this element

Returns:



86
87
88
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-microdata-2d8dbca83eec/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

Returns:

  • (Array<:text, :element, :attribute>)


78
79
80
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-microdata-2d8dbca83eec/lib/rdf/microdata/reader/nokogiri.rb', line 78

def text_content?
  @node.children.all? {|c| c.text?}
end

#to_strObject

Rational debug output



108
109
110
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/rdf-microdata-2d8dbca83eec/lib/rdf/microdata/reader/nokogiri.rb', line 108

def to_str
  @node.path
end