Class: Html::Tag
- Inherits:
-
Object
show all
- Defined in:
- lib/html/tag.rb
Constant Summary
collapse
- ALLOWED_CHILDREN =
[].freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(value = nil, **attrs) ⇒ Tag
Returns a new instance of Tag.
8
9
10
11
12
|
# File 'lib/html/tag.rb', line 8
def initialize(value = nil, **attrs)
@attributes = attrs
@value = value
valid_children?
end
|
Instance Attribute Details
#value ⇒ Object
Returns the value of attribute value.
6
7
8
|
# File 'lib/html/tag.rb', line 6
def value
@value
end
|
Instance Method Details
#attributes=(new_attributes) ⇒ Object
18
19
20
|
# File 'lib/html/tag.rb', line 18
def attributes=(new_attributes)
@attributes.merge!(new_attributes).compact!
end
|
#empty? ⇒ Boolean
26
27
28
29
30
|
# File 'lib/html/tag.rb', line 26
def empty?
return value.all?(&:empty?) if value.is_a?(Array)
value.nil? ? true : value&.empty?
end
|
#tag_name ⇒ Object
22
23
24
|
# File 'lib/html/tag.rb', line 22
def tag_name
nil
end
|
#to_s ⇒ Object
14
15
16
|
# File 'lib/html/tag.rb', line 14
def to_s
"<#{tag_name}#{read_attributes}>#{read_value}</#{tag_name}>"
end
|