class DoubleTag
Non-Self-Closing tag. Can have content, but doesn't have to.
Attributes
content[R]
oneline[RW]
Public Class Methods
new(element, attributes: nil, content: nil, oneline: false)
click to toggle source
Content represents everything between the opening and closing tags.
Calls superclass method
SingleTag::new
# 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
Public Instance Methods
add_content(addition)
click to toggle source
# File lib/objective_elements/double_tag.rb, line 23 def add_content(addition) @content << addition if addition @content.flatten! self end
Also aliased as: <<
content=(new)
click to toggle source
# File lib/objective_elements/double_tag.rb, line 14 def content=(new) reset_content add_content(new) end
reset_content()
click to toggle source
# File lib/objective_elements/double_tag.rb, line 19 def reset_content @content = [] end
to_a()
click to toggle source
# 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()
click to toggle source
# File lib/objective_elements/double_tag.rb, line 36 def to_s to_a.join(oneline ? '' : "\n") + "\n" end
Private Instance Methods
build_content_line(element)
click to toggle source
# File lib/objective_elements/double_tag.rb, line 42 def build_content_line(element) # Since DoubleTag inherits from SingleTag, it will slurp up those too. element.is_a?(SingleTag) ? element.to_a : element.to_s.dup end
closing_tag()
click to toggle source
# File lib/objective_elements/double_tag.rb, line 51 def closing_tag "</#{element}>" end
indent()
click to toggle source
# File lib/objective_elements/double_tag.rb, line 47 def indent "\ \ " end