Class: Ruby::Tags::NonVoid

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/tags/tags.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, *renders) ⇒ NonVoid

Returns a new instance of NonVoid.



41
42
43
44
45
# File 'lib/ruby/tags/tags.rb', line 41

def initialize(name, *renders)
  @name = name
  @attribute = renders.find { |r| r.is_a? Attribute } || Attribute.new
  @children = renders.reject { |r| r.is_a? Attribute }
end

Instance Method Details

#==(other) ⇒ Object



56
57
58
59
60
# File 'lib/ruby/tags/tags.rb', line 56

def ==(other)
  @name == other.instance_variable_get(:@name) &&
  @attribute == other.instance_variable_get(:@attribute) &&
  @children == other.instance_variable_get(:@children)
end

#add(tag) ⇒ Object



51
52
53
54
# File 'lib/ruby/tags/tags.rb', line 51

def add(tag)
  @children << tag
  self
end

#renderObject



47
48
49
# File 'lib/ruby/tags/tags.rb', line 47

def render
  @children.reduce("<#{@name}#{@attribute.render}>") { |m, t| m + t.render } + "</#{@name}>"
end