Class: SimpleHtml::Tag

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

Instance Method Summary collapse

Constructor Details

#initialize(name, content, attributes = {}) ⇒ Tag

Returns a new instance of Tag.



5
6
7
8
9
# File 'lib/simple_html.rb', line 5

def initialize(name, content, attributes = {})
  @name = name
  @content = content
  @attributes = attributes
end

Instance Method Details

#to_htmlObject



11
12
13
14
15
16
# File 'lib/simple_html.rb', line 11

def to_html
  attributes = @attributes.sort_by(&:first).
                           map { |key, value| " #{key}=\"#{value}\"" }.
                           join
  "<#{@name}#{attributes}>#{@content}</#{@name}>"
end