Class: RXSD::XML::LibXMLNode
Overview
Some additions to libxml xml node interface
Instance Attribute Summary
Attributes inherited from Node
Class Method Summary collapse
-
.xml_root(xml) ⇒ Object
Implementation of RXSD::XML::Node::xml_root(xml).
Instance Method Summary collapse
-
#attrs ⇒ Object
Implementation of RXSD::XML::Node.attrs.
-
#children ⇒ Object
Implementation of RXSD::XML::Node.children.
-
#content ⇒ Object
Implementation of RXSD::XML::Node.content See text? method as well.
-
#initialize(args = {}) ⇒ LibXMLNode
constructor
Create libxml node adapter w/ specified args, which may include * :node LibXML::Node to use to satify requests.
-
#name ⇒ Object
Implementation of RXSD::XML::Node.name.
-
#namespaces ⇒ Object
Implementation of RXSD::XML::Node.namespaces.
-
#parent ⇒ Object
Implementation of RXSD::XML::Node.parent.
-
#parent? ⇒ Boolean
Implementation of RXSD::XML::Node.parent?.
-
#text? ⇒ Boolean
Implementation of RXSD::XML::Node.text?.
Methods inherited from Node
#child_obj, #child_value, #child_values, #children_objs, factory, #root
Constructor Details
#initialize(args = {}) ⇒ LibXMLNode
Create libxml node adapter w/ specified args, which may include
-
:node LibXML::Node to use to satify requests
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/rxsd/libxml_adapter.rb', line 47 def initialize(args = {}) @node = args[:node] @parent = args[:parent] if args.has_key? :parent @attributes = @node.attributes.to_h @children = [] @node.children.find_all { |n| !n.text? }.each { |n| @children << LibXMLNode.new(:node => n, :parent => self) } @namespaces = [] @node.namespaces.each { |ns| @namespaces << LibXMLNamespace.new(:ns => ns) } end |
Class Method Details
.xml_root(xml) ⇒ Object
Implementation of RXSD::XML::Node::xml_root(xml)
41 42 43 |
# File 'lib/rxsd/libxml_adapter.rb', line 41 def self.xml_root(xml) LibXMLNode.new :node => LibXML::XML::Document.string(xml).root end |
Instance Method Details
#attrs ⇒ Object
Implementation of RXSD::XML::Node.attrs
71 72 73 |
# File 'lib/rxsd/libxml_adapter.rb', line 71 def attrs @attributes end |
#children ⇒ Object
Implementation of RXSD::XML::Node.children
88 89 90 |
# File 'lib/rxsd/libxml_adapter.rb', line 88 def children @children end |
#content ⇒ Object
Implementation of RXSD::XML::Node.content See text? method as well
100 101 102 103 104 |
# File 'lib/rxsd/libxml_adapter.rb', line 100 def content return nil unless text? @node.content if @node.text? @node.children[0].content end |
#name ⇒ Object
Implementation of RXSD::XML::Node.name
66 67 68 |
# File 'lib/rxsd/libxml_adapter.rb', line 66 def name @node.name end |
#namespaces ⇒ Object
Implementation of RXSD::XML::Node.namespaces
107 108 109 |
# File 'lib/rxsd/libxml_adapter.rb', line 107 def namespaces @namespaces end |
#parent ⇒ Object
Implementation of RXSD::XML::Node.parent
83 84 85 |
# File 'lib/rxsd/libxml_adapter.rb', line 83 def parent parent? ? @parent : nil end |
#parent? ⇒ Boolean
Implementation of RXSD::XML::Node.parent?
76 77 78 |
# File 'lib/rxsd/libxml_adapter.rb', line 76 def parent? @node.parent? && @node.parent.class != LibXML::XML::Document end |
#text? ⇒ Boolean
Implementation of RXSD::XML::Node.text?. See #content method as well
94 95 96 |
# File 'lib/rxsd/libxml_adapter.rb', line 94 def text? @node.text? || (@node.children.size == 1 && @node.children[0].text?) end |