Class: TBMX::HTML
- Inherits:
-
Object
- Object
- TBMX::HTML
- Defined in:
- lib/tbmx.rb
Instance Attribute Summary collapse
-
#lines ⇒ Object
readonly
Returns the value of attribute lines.
-
#paragraphs ⇒ Object
readonly
Returns the value of attribute paragraphs.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
-
#initialize(text) ⇒ HTML
constructor
A new instance of HTML.
- #parse ⇒ Object
- #parse_paragraph(paragraph) ⇒ Object
- #parse_paragraph_body(body) ⇒ Object
Constructor Details
#initialize(text) ⇒ HTML
Returns a new instance of HTML.
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
#lines ⇒ Object (readonly)
Returns the value of attribute lines.
43 44 45 |
# File 'lib/tbmx.rb', line 43 def lines @lines end |
#paragraphs ⇒ Object (readonly)
Returns the value of attribute paragraphs.
43 44 45 |
# File 'lib/tbmx.rb', line 43 def paragraphs @paragraphs end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
43 44 45 |
# File 'lib/tbmx.rb', line 43 def text @text end |
Instance Method Details
#parse ⇒ Object
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
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
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 |