Class: BetterHtml::Tree::Tag

Inherits:
Object
  • Object
show all
Defined in:
lib/better_html/tree/tag.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Tag

Returns a new instance of Tag.



9
10
11
12
# File 'lib/better_html/tree/tag.rb', line 9

def initialize(node)
  @node = node
  @start_solidus, @name_node, @attributes_node, @end_solidus = *node
end

Instance Attribute Details

#attributes_nodeObject (readonly)

Returns the value of attribute attributes_node.



7
8
9
# File 'lib/better_html/tree/tag.rb', line 7

def attributes_node
  @attributes_node
end

#end_solidusObject (readonly)

Returns the value of attribute end_solidus.



7
8
9
# File 'lib/better_html/tree/tag.rb', line 7

def end_solidus
  @end_solidus
end

#name_nodeObject (readonly)

Returns the value of attribute name_node.



7
8
9
# File 'lib/better_html/tree/tag.rb', line 7

def name_node
  @name_node
end

#nodeObject (readonly)

Returns the value of attribute node.



7
8
9
# File 'lib/better_html/tree/tag.rb', line 7

def node
  @node
end

#start_solidusObject (readonly)

Returns the value of attribute start_solidus.



7
8
9
# File 'lib/better_html/tree/tag.rb', line 7

def start_solidus
  @start_solidus
end

Class Method Details

.from_node(node) ⇒ Object



14
15
16
# File 'lib/better_html/tree/tag.rb', line 14

def self.from_node(node)
  new(node)
end

Instance Method Details

#attributesObject



34
35
36
# File 'lib/better_html/tree/tag.rb', line 34

def attributes
  @attributes ||= AttributesList.from_nodes(@attributes_node.to_a)
end

#closing?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/better_html/tree/tag.rb', line 26

def closing?
  @start_solidus&.type == :solidus
end

#locObject



18
19
20
# File 'lib/better_html/tree/tag.rb', line 18

def loc
  @node.loc
end

#nameObject



22
23
24
# File 'lib/better_html/tree/tag.rb', line 22

def name
  @name_node&.loc&.source&.downcase
end

#self_closing?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/better_html/tree/tag.rb', line 30

def self_closing?
  @end_solidus&.type == :solidus
end