Class: SyntaxTree::XML::Element

Inherits:
Node
  • Object
show all
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

Instance Method Summary collapse

Methods inherited from Node

#format, #pretty_print

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_tagObject (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

#contentObject (readonly)

Returns the value of attribute content.



281
282
283
# File 'lib/syntax_tree/xml/nodes.rb', line 281

def content
  @content
end

#locationObject (readonly)

Returns the value of attribute location.



281
282
283
# File 'lib/syntax_tree/xml/nodes.rb', line 281

def location
  @location
end

#opening_tagObject (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_nodesObject 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