Class: SyntaxTree::XML::Element
- Defined in:
- lib/syntax_tree/xml/nodes.rb
Overview
An element is a child of the document. It contains an opening tag, any optional content within the tag, and a closing tag. It can also potentially contain an opening tag that self-closes, in which case the content and closing tag will be nil.
Defined Under Namespace
Classes: ClosingTag, OpeningTag
Instance Attribute Summary collapse
-
#closing_tag ⇒ Object
readonly
Returns the value of attribute closing_tag.
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#opening_tag ⇒ Object
readonly
Returns the value of attribute opening_tag.
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
- #child_nodes ⇒ Object (also: #deconstruct)
- #deconstruct_keys(keys) ⇒ Object
-
#initialize(opening_tag:, content:, closing_tag:, location:) ⇒ Element
constructor
A new instance of Element.
Methods inherited from Node
Constructor Details
#initialize(opening_tag:, content:, closing_tag:, location:) ⇒ Element
283 284 285 286 287 288 |
# File 'lib/syntax_tree/xml/nodes.rb', line 283 def initialize(opening_tag:, content:, closing_tag:, location:) @opening_tag = opening_tag @content = content @closing_tag = closing_tag @location = location end |
Instance Attribute Details
#closing_tag ⇒ Object (readonly)
Returns the value of attribute closing_tag.
281 282 283 |
# File 'lib/syntax_tree/xml/nodes.rb', line 281 def closing_tag @closing_tag end |
#content ⇒ Object (readonly)
Returns the value of attribute content.
281 282 283 |
# File 'lib/syntax_tree/xml/nodes.rb', line 281 def content @content end |
#location ⇒ Object (readonly)
Returns the value of attribute location.
281 282 283 |
# File 'lib/syntax_tree/xml/nodes.rb', line 281 def location @location end |
#opening_tag ⇒ Object (readonly)
Returns the value of attribute opening_tag.
281 282 283 |
# File 'lib/syntax_tree/xml/nodes.rb', line 281 def opening_tag @opening_tag end |
Instance Method Details
#accept(visitor) ⇒ Object
290 291 292 |
# File 'lib/syntax_tree/xml/nodes.rb', line 290 def accept(visitor) visitor.visit_element(self) end |
#child_nodes ⇒ Object Also known as: deconstruct
294 295 296 |
# File 'lib/syntax_tree/xml/nodes.rb', line 294 def child_nodes [opening_tag, *content, closing_tag].compact end |
#deconstruct_keys(keys) ⇒ Object
300 301 302 303 304 305 306 307 |
# File 'lib/syntax_tree/xml/nodes.rb', line 300 def deconstruct_keys(keys) { opening_tag: opening_tag, content: content, closing_tag: closing_tag, location: location } end |