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.



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

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.



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

def attributes_node
  @attributes_node
end

#end_solidusObject (readonly)

Returns the value of attribute end_solidus.



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

def end_solidus
  @end_solidus
end

#name_nodeObject (readonly)

Returns the value of attribute name_node.



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

def name_node
  @name_node
end

#nodeObject (readonly)

Returns the value of attribute node.



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

def node
  @node
end

#start_solidusObject (readonly)

Returns the value of attribute start_solidus.



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

def start_solidus
  @start_solidus
end

Class Method Details

.from_node(node) ⇒ Object



12
13
14
# File 'lib/better_html/tree/tag.rb', line 12

def from_node(node)
  new(node)
end

Instance Method Details

#attributesObject



38
39
40
# File 'lib/better_html/tree/tag.rb', line 38

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

#closing?Boolean

Returns:

  • (Boolean)


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

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

#locObject



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

def loc
  @node.loc
end

#nameObject



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

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

#self_closing?Boolean

Returns:

  • (Boolean)


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

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