Class: HtmlParagraph

Inherits:
Object
  • Object
show all
Defined in:
lib/text-to-html/html_paragraph.rb

Overview

function: pulls text w/line breaks from clipboard, adds <p></p> to line breaks, and puts back on clipboard TODO: Enable classes

Instance Method Summary collapse

Constructor Details

#initialize(input, h_class) ⇒ HtmlParagraph

Returns a new instance of HtmlParagraph.



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/text-to-html/html_paragraph.rb', line 6

def initialize(input, h_class)
    # String to be parsed
    @input = input
    @hclass = h_class

    # Options
    @verbose = false
    @em = false
    @strong = false
    @use_class = false
end

Instance Method Details

#emObject



34
35
36
# File 'lib/text-to-html/html_paragraph.rb', line 34

def em
    @em = true
end

#strongObject



38
39
40
# File 'lib/text-to-html/html_paragraph.rb', line 38

def strong
    @strong = true
end

#to_paragraphObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/text-to-html/html_paragraph.rb', line 18

def to_paragraph
    raw_in = @input.gsub("\t", '').gsub("\r", '').gsub("\"", '').split("\n")
    puts raw_in.inspect if @verbose
    
    p_string = ""
    raw_in.each do | line | 
        if line.length > 0
            p_string << "<p>\n\t#{"<em>" if @em}#{"<strong>" if @strong}#{line}#{"</strong>" if @strong}#{"</em>" if @em}\n</p>\n"
        end
    end
    p_string.chomp!
    puts p_string if @verbose

    return p_string
end

#use_classObject



46
47
48
# File 'lib/text-to-html/html_paragraph.rb', line 46

def use_class
    @use_class = true
end

#verboseObject



42
43
44
# File 'lib/text-to-html/html_paragraph.rb', line 42

def verbose
    @verbose = true
end