Class: Traceability

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

Instance Attribute Summary collapse

Attributes inherited from BaseDocument

#dom, #headings, #id, #title

Instance Method Summary collapse

Methods inherited from BaseDocument

#save_html_to_file

Constructor Details

#initialize(top_doc, bottom_doc) ⇒ Traceability

Returns a new instance of Traceability.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/almirah/doc_types/traceability.rb', line 11

def initialize(top_doc, bottom_doc)
    super()
    @top_doc = top_doc
    @bottom_doc = bottom_doc
    @is_agregated = if bottom_doc
                      false
                    else
                      true
                    end
    @traced_items = {}

    if @is_agregated 
        @id = top_doc.id + "-all"
    else
        @id = top_doc.id + "-" + bottom_doc.id
    end

    @title = "Traceability Matrix: " + @id
end

Instance Attribute Details

#bottom_docObject

Returns the value of attribute bottom_doc.



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

def bottom_doc
  @bottom_doc
end

#is_agregatedObject

Returns the value of attribute is_agregated.



8
9
10
# File 'lib/almirah/doc_types/traceability.rb', line 8

def is_agregated
  @is_agregated
end

#itemsObject

Returns the value of attribute items.



7
8
9
# File 'lib/almirah/doc_types/traceability.rb', line 7

def items
  @items
end

#top_docObject

Returns the value of attribute top_doc.



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

def top_doc
  @top_doc
end

#traced_itemsObject

Returns the value of attribute traced_items.



9
10
11
# File 'lib/almirah/doc_types/traceability.rb', line 9

def traced_items
  @traced_items
end

Instance Method Details

#render_table_row(top_item) ⇒ Object



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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/almirah/doc_types/traceability.rb', line 64

def render_table_row(top_item)
    s = ""
    top_f_text = top_item.format_string( top_item.text )
    id_color = ""

    if top_item.down_links

        if @is_agregated
            
            top_item_rendered = false

            top_item.down_links.each do |bottom_item|
                id_color = "style='background-color: ##{bottom_item.parent_doc.color};'"
                bottom_f_text = bottom_item.format_string( bottom_item.text )
                document_section = bottom_item.parent_heading.
                s += "\t<tr>\n"
                s += "\t\t<td class=\"item_id\"><a href=\"./../#{top_item.parent_doc.id}/#{top_item.parent_doc.id}.html##{top_item.id}\" class=\"external\">#{top_item.id}</a></td>\n"
                s += "\t\t<td class=\"item_text\" style='width: 34%;'>#{top_f_text}</td>\n"
                s += "\t\t<td class=\"item_id\" #{id_color}><a href=\"./../#{bottom_item.parent_doc.id}/#{bottom_item.parent_doc.id}.html##{bottom_item.id}\" class=\"external\">#{bottom_item.id}</a></td>\n"
                s += "\t\t<td class=\"item_text\" style='width: 34%;'>#{bottom_f_text}</td>\n"
                s += "\t\t<td class=\"item_text\" style='width: 16%;'>#{document_section}</td>\n"
                s += "\t</tr>\n"
                top_item_rendered = true
                @traced_items[top_item.id.to_s.downcase] = top_item
            end
            unless top_item_rendered
                s += "\t<tr>\n"
                s += "\t\t<td class=\"item_id\"><a href=\"./../#{top_item.parent_doc.id}/#{top_item.parent_doc.id}.html##{top_item.id}\" class=\"external\">#{top_item.id}</a></td>\n"
                s += "\t\t<td class=\"item_text\" style='width: 34%;'>#{top_f_text}</td>\n"
                s += "\t\t<td class=\"item_id\"></td>\n"
                s += "\t\t<td class=\"item_text\" style='width: 34%;'></td>\n"
                s += "\t\t<td class=\"item_text\" style='width: 16%;'></td>\n"
                s += "\t</tr>\n"
            end

        else
            top_item_rendered = false
            top_item.down_links.each do |bottom_item|

                id_color = ""

                if bottom_item.parent_doc.id == @bottom_doc.id

                    bottom_f_text = bottom_item.format_string( bottom_item.text )
                    document_section = bottom_item.parent_heading.

                    s += "\t<tr>\n"
                    s += "\t\t<td class=\"item_id\" #{id_color}><a href=\"./../#{top_item.parent_doc.id}/#{top_item.parent_doc.id}.html##{top_item.id}\" class=\"external\">#{top_item.id}</a></td>\n"
                    s += "\t\t<td class=\"item_text\" style='width: 34%;'>#{top_f_text}</td>\n"
                    s += "\t\t<td class=\"item_id\"><a href=\"./../#{bottom_item.parent_doc.id}/#{bottom_item.parent_doc.id}.html##{bottom_item.id}\" class=\"external\">#{bottom_item.id}</a></td>\n"
                    s += "\t\t<td class=\"item_text\" style='width: 34%;'>#{bottom_f_text}</td>\n"
                    s += "\t\t<td class=\"item_text\" style='width: 16%;'>#{document_section}</td>\n"
                    s += "\t</tr>\n"
                    top_item_rendered = true
                    @traced_items[top_item.id.to_s.downcase] = top_item
                end
            end
            unless top_item_rendered
                s += "\t<tr>\n"
                s += "\t\t<td class=\"item_id\" #{id_color}><a href=\"./../#{top_item.parent_doc.id}/#{top_item.parent_doc.id}.html##{top_item.id}\" class=\"external\">#{top_item.id}</a></td>\n"
                s += "\t\t<td class=\"item_text\" style='width: 34%;'>#{top_f_text}</td>\n"
                s += "\t\t<td class=\"item_id\"></td>\n"
                s += "\t\t<td class=\"item_text\" style='width: 34%;'></td>\n"
                s += "\t\t<td class=\"item_text\" style='width: 16%;'></td>\n"
                s += "\t</tr>\n"
            end
        end
    else
        s += "\t<tr>\n"
        s += "\t\t<td class=\"item_id\"><a href=\"./../#{top_item.parent_doc.id}/#{top_item.parent_doc.id}.html##{top_item.id}\" class=\"external\">#{top_item.id}</a></td>\n"
        s += "\t\t<td class=\"item_text\" style='width: 34%;'>#{top_f_text}</td>\n"
        s += "\t\t<td class=\"item_id\"></td>\n"
        s += "\t\t<td class=\"item_text\" style='width: 34%;'></td>\n"
        s += "\t\t<td class=\"item_text\" style='width: 16%;'></td>\n"
        s += "\t</tr>\n"
    end
    return s
end

#to_consoleObject



31
32
33
# File 'lib/almirah/doc_types/traceability.rb', line 31

def to_console
    puts "\e[35m" + "Traceability: " + @id + "\e[0m"
end

#to_html(nav_pane, output_file_path) ⇒ Object



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
# File 'lib/almirah/doc_types/traceability.rb', line 35

def to_html(nav_pane, output_file_path)

    html_rows = Array.new

    html_rows.append('')
    s = "<h1>#{@title}</h1>\n"
    s += "<table class=\"controlled\">\n"
    s += "\t<thead> <th>#</th> <th style='font-weight: bold;'>#{@top_doc.title}</th> "
    if @bottom_doc
        s += "<th>#</th> <th style='font-weight: bold;'>#{@bottom_doc.title}</th> "
    else
        s += "<th>#</th> <th style='font-weight: bold;'>All References</th> "
    end
    s += "<th style='font-weight: bold;'>Document Section</th>"
    s += "</thead>\n"
    html_rows.append s

    sorted_items = @top_doc.controlled_items.sort_by { |w| w.id }

    sorted_items.each do |top_item|
        row = render_table_row top_item
        html_rows.append row
    end
    html_rows.append "</table>\n"

    self.save_html_to_file(html_rows, nav_pane, output_file_path)
    
end