Class: TBMX::HTML

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text) ⇒ HTML

Returns a new instance of HTML.

Raises:

  • (ArgumentError)


45
46
47
48
49
50
# File 'lib/tbmx.rb', line 45

def initialize(text)
  raise ArgumentError if not text.is_a? String
  @text = text
  @lines = text.split("\n").map &:strip
  @paragraphs = @lines.split ""
end

Instance Attribute Details

#linesObject (readonly)

Returns the value of attribute lines.



43
44
45
# File 'lib/tbmx.rb', line 43

def lines
  @lines
end

#paragraphsObject (readonly)

Returns the value of attribute paragraphs.



43
44
45
# File 'lib/tbmx.rb', line 43

def paragraphs
  @paragraphs
end

#textObject (readonly)

Returns the value of attribute text.



43
44
45
# File 'lib/tbmx.rb', line 43

def text
  @text
end

Instance Method Details

#parseObject



66
67
68
# File 'lib/tbmx.rb', line 66

def parse
  paragraphs.map {|paragraph| parse_paragraph paragraph}.join "\n\n"
end

#parse_paragraph(paragraph) ⇒ Object

Raises:

  • (ArgumentError)


57
58
59
60
61
62
63
64
# File 'lib/tbmx.rb', line 57

def parse_paragraph(paragraph)
  raise ArgumentError if not paragraph.is_a? Array
  paragraph.each {|line| raise ArgumentError if not line.is_a? String}
  body = paragraph.map do |line|
    html_escape line
  end.join "\n"
  "<p>#{parse_paragraph_body body}</p>"
end

#parse_paragraph_body(body) ⇒ Object

Raises:

  • (ArgumentError)


52
53
54
55
# File 'lib/tbmx.rb', line 52

def parse_paragraph_body(body)
  raise ArgumentError if not body.is_a? String
  body
end