Class: DoubleTag

Inherits:
SingleTag show all
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

Attributes inherited from SingleTag

#attributes, #element

Instance Method Summary collapse

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

#contentObject

Returns the value of attribute content.



4
5
6
# File 'lib/objective_elements/double_tag.rb', line 4

def content
  @content
end

#onelineObject

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_contentObject



19
20
21
# File 'lib/objective_elements/double_tag.rb', line 19

def reset_content
  @content = []
end

#to_aObject



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_sObject



36
37
38
# File 'lib/objective_elements/double_tag.rb', line 36

def to_s
  to_a.join(oneline ? '' : "\n") + "\n"
end