Class: Html_Report

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

Instance Method Summary collapse

Constructor Details

#initialize(reportName, rows) ⇒ Html_Report

Returns a new instance of Html_Report.



2
3
4
5
6
# File 'lib/driller/html_report.rb', line 2

def initialize(reportName, rows)   
    @reportName = reportName     
    @html = ""
    createTable(rows)
end

Instance Method Details

#addHeading(row) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/driller/html_report.rb', line 28

def addHeading(row)
    @html = "#{@html}<tr>"
    row.each do |key, value|
        @html = "#{@html}<th>"
        @html = "#{@html} #{(key.to_s).capitalize}"
        @html = "#{@html}</th>"
    end
    @html = @html + "</tr>"
end

#addRow(row) ⇒ Object



38
39
40
41
42
43
44
45
46
# File 'lib/driller/html_report.rb', line 38

def addRow(row)
    @html = @html + "<tr>"
    row.each do |key, value|
        @html = "#{@html}<td>"
        @html = "#{@html}#{value}"
        @html = "#{@html}</td>"
    end
    @html = @html + "</tr>"
end

#createTable(rows) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/driller/html_report.rb', line 8

def createTable(rows)

    if rows.length == 0
        @html = "#{@html}<tr><td>There are no #{@reportName}.</td></tr>"
        return 
    end

    addHeading(rows[0])

    if rows.kind_of?(Array)
        rows.each do |row|
            unless row.nil?
                addRow(row)
            end
        end
    else 
        abort("Rows should be an array in Html_Report");
    end
end

#getReportObject



48
49
50
51
52
53
54
55
56
# File 'lib/driller/html_report.rb', line 48

def getReport
  
    @htmlWithWrapper = "<!DOCTYPE html><html><head><title>Report</title></head><body>"
    @htmlWithWrapper = @htmlWithWrapper + "<h1>#{@reportName.capitalize}</h1>"
    @htmlWithWrapper = @htmlWithWrapper + "<table class='table'>#{@html}</table>"
    @htmlWithWrapper = @htmlWithWrapper + "</body></html>"
    
    return @htmlWithWrapper
end