Class: Traceability
- Inherits:
-
BaseDocument
- Object
- BaseDocument
- Traceability
- Defined in:
- lib/almirah/doc_types/traceability.rb
Instance Attribute Summary collapse
-
#bottom_doc ⇒ Object
Returns the value of attribute bottom_doc.
-
#is_agregated ⇒ Object
Returns the value of attribute is_agregated.
-
#items ⇒ Object
Returns the value of attribute items.
-
#top_doc ⇒ Object
Returns the value of attribute top_doc.
-
#traced_items ⇒ Object
Returns the value of attribute traced_items.
Attributes inherited from BaseDocument
#dom, #headings, #id, #output_rel_path, #title
Instance Method Summary collapse
-
#initialize(top_doc, bottom_doc) ⇒ Traceability
constructor
A new instance of Traceability.
- #render_table_row(top_item) ⇒ Object
- #to_console ⇒ Object
- #to_html(nav_pane, output_file_path) ⇒ Object
Methods inherited from BaseDocument
#critical_chain_link, #decisions_link, #home_link, #index_link, #needs_chartjs?, #rel_to, #save_html_to_file
Constructor Details
#initialize(top_doc, bottom_doc) ⇒ Traceability
Returns a new instance of Traceability.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/almirah/doc_types/traceability.rb', line 6 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 = {} @id = if @is_agregated top_doc.id + '-all' else top_doc.id + '-' + bottom_doc.id end @title = 'Traceability Matrix: ' + @id end |
Instance Attribute Details
#bottom_doc ⇒ Object
Returns the value of attribute bottom_doc.
4 5 6 |
# File 'lib/almirah/doc_types/traceability.rb', line 4 def bottom_doc @bottom_doc end |
#is_agregated ⇒ Object
Returns the value of attribute is_agregated.
4 5 6 |
# File 'lib/almirah/doc_types/traceability.rb', line 4 def is_agregated @is_agregated end |
#items ⇒ Object
Returns the value of attribute items.
4 5 6 |
# File 'lib/almirah/doc_types/traceability.rb', line 4 def items @items end |
#top_doc ⇒ Object
Returns the value of attribute top_doc.
4 5 6 |
# File 'lib/almirah/doc_types/traceability.rb', line 4 def top_doc @top_doc end |
#traced_items ⇒ Object
Returns the value of attribute traced_items.
4 5 6 |
# File 'lib/almirah/doc_types/traceability.rb', line 4 def traced_items @traced_items 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 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# 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) 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.get_section_info_html 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 = '' next unless bottom_item.parent_doc.id == @bottom_doc.id bottom_f_text = bottom_item.format_string(bottom_item.text) document_section = bottom_item.parent_heading.get_section_info_html 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 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 s end |
#to_console ⇒ Object
26 27 28 |
# File 'lib/almirah/doc_types/traceability.rb', line 26 def to_console puts "\e[35m" + 'Traceability: ' + @id + "\e[0m" end |
#to_html(nav_pane, output_file_path) ⇒ Object
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 |
# File 'lib/almirah/doc_types/traceability.rb', line 30 def to_html(nav_pane, output_file_path) html_rows = [] 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 += if @bottom_doc "<th>#</th> <th style='font-weight: bold;'>#{@bottom_doc.title}</th> " else "<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" save_html_to_file(html_rows, nav_pane, output_file_path) end |