Class: SXRB::Node
- Inherits:
-
Struct
- Object
- Struct
- SXRB::Node
- Defined in:
- lib/sxrb/node.rb
Overview
Node class is simple DOM-like element, which allows easy travesing through restricted part of document structure with #children and #parent methods.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#children ⇒ Object
Returns the value of attribute children.
-
#name ⇒ Object
Returns the value of attribute name.
-
#namespaces ⇒ Object
Returns the value of attribute namespaces.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
-
#append(node) ⇒ Object
private
Internal method used to build DOM-like structure.
-
#content ⇒ String
Returns text content of a node (recursively), skipping all markup.
-
#initialize(*args, &block) ⇒ Node
constructor
private
Internal method used to build DOM-like structure.
Constructor Details
#initialize(*args, &block) ⇒ Node
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Internal method used to build DOM-like structure.
8 9 10 11 |
# File 'lib/sxrb/node.rb', line 8 def initialize(*args, &block) super(*args, &block) @children = [] end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes
4 5 6 |
# File 'lib/sxrb/node.rb', line 4 def attributes @attributes end |
#children ⇒ Object
Returns the value of attribute children.
5 6 7 |
# File 'lib/sxrb/node.rb', line 5 def children @children end |
#name ⇒ Object
Returns the value of attribute name
4 5 6 |
# File 'lib/sxrb/node.rb', line 4 def name @name end |
#namespaces ⇒ Object
Returns the value of attribute namespaces
4 5 6 |
# File 'lib/sxrb/node.rb', line 4 def namespaces @namespaces end |
#parent ⇒ Object
Returns the value of attribute parent
4 5 6 |
# File 'lib/sxrb/node.rb', line 4 def parent @parent end |
#prefix ⇒ Object
Returns the value of attribute prefix
4 5 6 |
# File 'lib/sxrb/node.rb', line 4 def prefix @prefix end |
#uri ⇒ Object
Returns the value of attribute uri
4 5 6 |
# File 'lib/sxrb/node.rb', line 4 def uri @uri end |
Instance Method Details
#append(node) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Internal method used to build DOM-like structure.
15 16 17 18 |
# File 'lib/sxrb/node.rb', line 15 def append(node) node.parent = self @children << node end |
#content ⇒ String
Returns text content of a node (recursively), skipping all markup.
25 26 27 |
# File 'lib/sxrb/node.rb', line 25 def content children.map {|child| child.is_a?(TextNode)? child.text : child.content}.flatten.join('') end |