Class: RuBB::Node::URL

Inherits:
RuBB::Node show all
Defined in:
lib/rubb/node/url.rb

Instance Attribute Summary collapse

Attributes inherited from RuBB::Node

#children

Instance Method Summary collapse

Methods inherited from RuBB::Node

#<<

Constructor Details

#initialize(options = {}) ⇒ URL

Returns a new instance of URL.



6
7
8
9
# File 'lib/rubb/node/url.rb', line 6

def initialize(options={})
  super(options)
  @url = options[:url] || ''
end

Instance Attribute Details

#urlObject

Returns the value of attribute url.



4
5
6
# File 'lib/rubb/node/url.rb', line 4

def url
  @url
end

Instance Method Details

#to_htmlObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rubb/node/url.rb', line 11

def to_html
  unless(@url.empty?)
    html = "<a href=\"#{Parser.escape_quotes(@url)}\">"
    @children.each do |child|
      html += child ? child.to_html : ''
    end
    html + '</a>'
  else
    url = Parser.escape_quotes(@children.map {|c| c ? c.to_html : '' }.join)
    html = "<a href=\"#{url}\">#{url}</a>"
  end
end