Class: DoubleTag
- Defined in:
- lib/objective_elements/double_tag.rb
Overview
Non-Self-Closing tag. Can have content, but doesn’t have to.
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.
8 9 10 11 12 |
# File 'lib/objective_elements/double_tag.rb', line 8 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.
4 5 6 |
# File 'lib/objective_elements/double_tag.rb', line 4 def content @content end |
#oneline ⇒ Object
Returns the value of attribute oneline.
3 4 5 |
# File 'lib/objective_elements/double_tag.rb', line 3 def oneline @oneline end |
Instance Method Details
#add_content(addition) ⇒ Object Also known as: <<
23 24 25 26 27 |
# File 'lib/objective_elements/double_tag.rb', line 23 def add_content(addition) @content << addition if addition @content.flatten! self end |
#reset_content ⇒ Object
19 20 21 |
# File 'lib/objective_elements/double_tag.rb', line 19 def reset_content @content = [] end |
#to_a ⇒ Object
30 31 32 33 34 |
# File 'lib/objective_elements/double_tag.rb', line 30 def to_a lines = content.map { |c| build_content_line c } lines = lines.flatten.map { |l| l.prepend oneline ? '' : indent } lines.unshift(opening_tag).push(closing_tag) end |
#to_s ⇒ Object
36 37 38 |
# File 'lib/objective_elements/double_tag.rb', line 36 def to_s to_a.join(oneline ? '' : "\n") + "\n" end |