Class: RuBB::Node::Text

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

Instance Attribute Summary collapse

Attributes inherited from RuBB::Node

#children

Instance Method Summary collapse

Methods inherited from RuBB::Node

#<<

Constructor Details

#initialize(options = {}) ⇒ Text

Returns a new instance of Text.



7
8
9
10
11
# File 'lib/rubb/node/text.rb', line 7

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

Instance Attribute Details

#ignore_whitespaceObject

Returns the value of attribute ignore_whitespace.



5
6
7
# File 'lib/rubb/node/text.rb', line 5

def ignore_whitespace
  @ignore_whitespace
end

#textObject

Returns the value of attribute text.



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

def text
  @text
end

Instance Method Details

#to_htmlObject



13
14
15
16
17
18
19
# File 'lib/rubb/node/text.rb', line 13

def to_html
  if(@ignore_whitespace)
    @text.gsub(/\s/, '')
  else
    @text.gsub(/\r\n?/, "\n").gsub(/\n/, '<br />')
  end
end