Class: SyntaxTree::XML::Attribute

Inherits:
Node
  • Object
show all
Defined in:
lib/syntax_tree/xml/nodes.rb

Overview

An Attribute is a key-value pair within a tag. It contains the key, the equals sign, and the value.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#format, #pretty_print

Constructor Details

#initialize(key:, equals:, value:, location:) ⇒ Attribute

Returns a new instance of Attribute.



340
341
342
343
344
345
# File 'lib/syntax_tree/xml/nodes.rb', line 340

def initialize(key:, equals:, value:, location:)
  @key = key
  @equals = equals
  @value = value
  @location = location
end

Instance Attribute Details

#equalsObject (readonly)

Returns the value of attribute equals.



338
339
340
# File 'lib/syntax_tree/xml/nodes.rb', line 338

def equals
  @equals
end

#keyObject (readonly)

Returns the value of attribute key.



338
339
340
# File 'lib/syntax_tree/xml/nodes.rb', line 338

def key
  @key
end

#locationObject (readonly)

Returns the value of attribute location.



338
339
340
# File 'lib/syntax_tree/xml/nodes.rb', line 338

def location
  @location
end

#valueObject (readonly)

Returns the value of attribute value.



338
339
340
# File 'lib/syntax_tree/xml/nodes.rb', line 338

def value
  @value
end

Instance Method Details

#accept(visitor) ⇒ Object



347
348
349
# File 'lib/syntax_tree/xml/nodes.rb', line 347

def accept(visitor)
  visitor.visit_attribute(self)
end

#child_nodesObject Also known as: deconstruct



351
352
353
# File 'lib/syntax_tree/xml/nodes.rb', line 351

def child_nodes
  [key, equals, value]
end

#deconstruct_keys(keys) ⇒ Object



357
358
359
# File 'lib/syntax_tree/xml/nodes.rb', line 357

def deconstruct_keys(keys)
  { key: key, equals: equals, value: value, location: location }
end