Class: Index

Inherits:
BaseDocument show all
Defined in:
lib/almirah/doc_types/index.rb

Instance Attribute Summary collapse

Attributes inherited from BaseDocument

#headings, #id, #path, #title

Instance Method Summary collapse

Methods inherited from BaseDocument

#save_html_to_file

Constructor Details

#initialize(project) ⇒ Index

Returns a new instance of Index.



8
9
10
11
12
13
14
# File 'lib/almirah/doc_types/index.rb', line 8

def initialize(project)
    @items = Array.new
    @project = project

    @title = "Document Index"
    @id = "index"
end

Instance Attribute Details

#itemsObject

Returns the value of attribute items.



5
6
7
# File 'lib/almirah/doc_types/index.rb', line 5

def items
  @items
end

#projectObject

Returns the value of attribute project.



6
7
8
# File 'lib/almirah/doc_types/index.rb', line 6

def project
  @project
end

Instance Method Details

#to_consoleObject



16
17
18
# File 'lib/almirah/doc_types/index.rb', line 16

def to_console
    puts "\e[36m" + "Index: " + @id + "\e[0m"
end

#to_html(output_file_path) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/almirah/doc_types/index.rb', line 20

def to_html(output_file_path)

    html_rows = Array.new

    html_rows.append('')
    s = "<h1>#{@title}</h1>\n"

    # Specifications
    s = "<h2>Specifications</h2>\n"
    s += "<table class=\"controlled\">\n"
    s += "\t<thead>\n"
    s += "\t\t<th>Title</th>\n"
    s += "\t\t<th>Items</th>\n"
    s += "\t\t<th>Items<br>w/ Uplinks</th>\n"
    s += "\t\t<th>Items<br>w/ Downlinks</th>\n"
    s += "\t\t<th>Covered<br>by Tests</th>\n"
    s += "\t\t<th>Duplicated<br>ids</th>\n"
    s += "\t\t<th>TODOs</th>\n"
    s += "\t\t<th>Last Used<br>id</th>\n"
    s += "</thead>\n"
    html_rows.append s

    sorted_items = @project.specifications.sort_by { |w| w.id }

    sorted_items.each do |doc|
        s = "\t<tr>\n"
        s += "\t\t<td class=\"item_text\" style='padding: 5px;'><a href=\"./specifications/#{doc.id}/#{doc.id}.html\" class=\"external\">#{doc.title}</a></td>\n"
        s += "\t\t<td class=\"item_id\" style='width: 7%;'>#{doc.controlled_items.length.to_s}</td>\n"
        s += "\t\t<td class=\"item_id\" style='width: 7%;'>#{doc.items_with_uplinks_number.to_s}</td>\n"
        s += "\t\t<td class=\"item_id\" style='width: 7%;'>#{doc.items_with_downlinks_number.to_s}</td>\n"
        s += "\t\t<td class=\"item_id\" style='width: 7%;'>#{doc.items_with_coverage_number.to_s}</td>\n"
        
        if doc.duplicated_ids_number >0
            s += "\t\t<td class=\"item_id\" style='width: 7%; background-color: #fcc;'>"
            s += "<div id=\"DL_#{doc.id}\" style=\"display: block;\">"
            s += "<a  href=\"#\" onclick=\"downlink_OnClick(this.parentElement); return false;\" class=\"external\">#{doc.duplicated_ids_number.to_s}</a>"
            s += "</div>"
            s += "<div id=\"DLS_#{doc.id}\" style=\"display: none;\">"
            doc.duplicates_list.each do |lnk|
                s += "\t\t\t<a href=\"./specifications/#{doc.id}/#{doc.id}.html##{lnk.id}\" class=\"external\">#{lnk.id}</a>\n<br>"
            end
            s += "</div>"
            s += "</td>\n"
        else
            s += "\t\t<td class=\"item_id\" style='width: 7%;'>#{doc.duplicated_ids_number.to_s}</td>\n"
        end
        if doc.todo_blocks.length >0
            color = "background-color: #fcc;"
        else
            color = ""
        end
        s += "\t\t<td class=\"item_id\" style='width: 7%; #{color}'>#{doc.todo_blocks.length.to_s}</td>\n"
        s += "\t\t<td class=\"item_id\" style='width: 7%;'>#{doc.last_used_id.to_s}</td>\n"
        s += "</tr>\n"
        html_rows.append s
    end
    html_rows.append "</table>\n"

    # Traceability Matrices
    s = "<h2>Traceability Matrices</h2>\n"
    s += "<table class=\"controlled\">\n"
    s += "\t<thead>\n"
    s += "\t\t<th>Title</th>\n"
    s += "\t\t<th>Top Document</th>\n"
    s += "\t\t<th>Bottom Document</th>\n"
    s += "</thead>\n"
    html_rows.append s

    sorted_items = @project.traceability_matrices.sort_by { |w| w.id }

    sorted_items.each do |doc|
        s = "\t<tr>\n"
        s += "\t\t<td class=\"item_text\" style='padding: 5px;'><a href=\"./specifications/#{doc.id}/#{doc.id}.html\" class=\"external\">#{doc.title}</a></td>\n"
        s += "\t\t<td class=\"item_text\" style='width: 25%; padding: 5px;'>#{doc.top_doc.title}</td>\n"
        s += "\t\t<td class=\"item_text\" style='width: 25%; padding: 5px;'>#{doc.bottom_doc.title}</td>\n"
        s += "</tr>\n"
        html_rows.append s
    end
    html_rows.append "</table>\n"

    # Coverage Matrices
    if @project.coverage_matrices.length > 0
        s = "<h2>Coverage Matrices</h2>\n"
        s += "<table class=\"controlled\">\n"
        s += "\t<thead>\n"
        s += "\t\t<th>Title</th>\n"
        s += "\t\t<th>Specification Covered</th>\n"
        s += "</thead>\n"
        html_rows.append s

        sorted_items = @project.coverage_matrices.sort_by { |w| w.id }

        sorted_items.each do |doc|
            s = "\t<tr>\n"
            s += "\t\t<td class=\"item_text\" style='padding: 5px;'><a href=\"./specifications/#{doc.id}/#{doc.id}.html\" class=\"external\">#{doc.title}</a></td>\n"
            s += "\t\t<td class=\"item_text\" style='width: 25%; padding: 5px;'>#{doc.top_doc.title}</td>\n"
            s += "</tr>\n"
            html_rows.append s
        end
        html_rows.append "</table>\n"
    end

    self.save_html_to_file(html_rows, nil, output_file_path)
    
end