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.

Direct Known Subclasses

ShelfTag

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.



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

#contentObject

Returns the value of attribute content.



6
7
8
# File 'lib/objective_elements/double_tag.rb', line 6

def content
  @content
end

#onelineObject

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_contentObject



21
22
23
# File 'lib/objective_elements/double_tag.rb', line 21

def reset_content
  @content = []
end

#to_aObject



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_sObject



38
39
40
# File 'lib/objective_elements/double_tag.rb', line 38

def to_s
  "#{to_a.join(oneline ? '' : "\n")}\n"
end