Class: DoubleTag
- Defined in:
- lib/objective_elements/double_tag.rb
Overview
Non-Self-Closing tag. Can have content, but doesn't have to.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#oneline ⇒ Object
Returns the value of attribute oneline.
Attributes inherited from SingleTag
Instance Method Summary collapse
- #add_content(addition) ⇒ Object (also: #<<)
-
#initialize(element, attributes: nil, content: nil, oneline: false) ⇒ DoubleTag
constructor
Content represents everything between the opening and closing tags.
- #reset_content ⇒ Object
- #to_a ⇒ Object
- #to_s ⇒ Object
Methods inherited from SingleTag
#add_parent, #method_missing, #reset_attributes, #respond_to_missing?
Constructor Details
#initialize(element, attributes: nil, content: nil, oneline: false) ⇒ DoubleTag
Content represents everything between the opening and closing tags.
10 11 12 13 14 |
# File 'lib/objective_elements/double_tag.rb', line 10 def initialize(element, attributes: nil, content: nil, oneline: false) @oneline = oneline self.content = content super(element, attributes: attributes) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class SingleTag
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
6 7 8 |
# File 'lib/objective_elements/double_tag.rb', line 6 def content @content end |
#oneline ⇒ Object
Returns the value of attribute oneline.
5 6 7 |
# File 'lib/objective_elements/double_tag.rb', line 5 def oneline @oneline end |
Instance Method Details
#add_content(addition) ⇒ Object Also known as: <<
25 26 27 28 29 |
# File 'lib/objective_elements/double_tag.rb', line 25 def add_content(addition) @content << addition if addition @content.flatten! self end |
#reset_content ⇒ Object
21 22 23 |
# File 'lib/objective_elements/double_tag.rb', line 21 def reset_content @content = [] end |
#to_a ⇒ Object
32 33 34 35 36 |
# File 'lib/objective_elements/double_tag.rb', line 32 def to_a lines = content.map { |c| build_content_line c } lines = lines.flatten.map { |l| oneline ? l : indent + l } lines.unshift(opening_tag).push(closing_tag) end |
#to_s ⇒ Object
38 39 40 |
# File 'lib/objective_elements/double_tag.rb', line 38 def to_s "#{to_a.join(oneline ? '' : "\n")}\n" end |