Class: Traceability

Inherits:
BaseDocument show all
Defined in:
lib/almirah/doc_types/traceability.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(top_doc, bottom_doc, is_agregated) ⇒ Traceability

Returns a new instance of Traceability.



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

def initialize(top_doc, bottom_doc, is_agregated)

    @top_doc = top_doc
    @bottom_doc = bottom_doc
    @is_agregated = is_agregated

    @items = Array.new
    @headings = Array.new

    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

Instance Method Details

#render_table_row(top_item) ⇒ Object



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

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

    if top_item.down_links

        if @is_agregated

            if top_item.down_links.length > 1
                id_color = "style='background-color: #fff8c5;'"
            else
                id_color = ""
            end

            top_item.down_links.each do |bottom_item|
                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"
            end

        else
            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"
                end
            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



28
29
30
# File 'lib/almirah/doc_types/traceability.rb', line 28

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

#to_html(nav_pane, output_file_path) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/almirah/doc_types/traceability.rb', line 32

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> "
    s += "<th>#</th> <th style='font-weight: bold;'>#{@bottom_doc.title}</th> "
    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