Class: ControlledParagraph

Inherits:
Paragraph show all
Defined in:
lib/almirah/doc_items/controlled_paragraph.rb

Overview

<REQ> Implementa a controlled paragraph as a subclass of the DocItem >[SRS-001] </REQ>

Direct Known Subclasses

SourceCodeParagraph

Instance Attribute Summary collapse

Attributes inherited from Paragraph

#text

Attributes inherited from DocItem

#parent_doc, #parent_heading

Instance Method Summary collapse

Methods inherited from Paragraph

#getTextWithoutSpaces

Methods inherited from DocItem

#get_url

Methods inherited from TextLine

add_lazy_doc_id, #bold, #bold_and_italic, #format_string, #inline_code, #italic, #link

Methods inherited from TextLineBuilderContext

#bold, #bold_and_italic, #inline_code, #italic, #link

Constructor Details

#initialize(doc, text, id) ⇒ ControlledParagraph

Returns a new instance of ControlledParagraph.



7
8
9
10
11
12
13
14
15
16
# File 'lib/almirah/doc_items/controlled_paragraph.rb', line 7

def initialize(doc, text, id)
  super(doc, text)
  @parent_heading = doc.headings[-1]
  @id = id
  @up_link_ids = nil
  @down_links = nil
  @coverage_links = nil
  @source_code_links = nil
  @decision_record_links = nil
end

Instance Attribute Details

Returns the value of attribute coverage_links.



5
6
7
# File 'lib/almirah/doc_items/controlled_paragraph.rb', line 5

def coverage_links
  @coverage_links
end

Returns the value of attribute decision_record_links.



5
6
7
# File 'lib/almirah/doc_items/controlled_paragraph.rb', line 5

def decision_record_links
  @decision_record_links
end

Returns the value of attribute down_links.



5
6
7
# File 'lib/almirah/doc_items/controlled_paragraph.rb', line 5

def down_links
  @down_links
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/almirah/doc_items/controlled_paragraph.rb', line 5

def id
  @id
end

Returns the value of attribute source_code_links.



5
6
7
# File 'lib/almirah/doc_items/controlled_paragraph.rb', line 5

def source_code_links
  @source_code_links
end

Returns the value of attribute up_link_ids.



5
6
7
# File 'lib/almirah/doc_items/controlled_paragraph.rb', line 5

def up_link_ids
  @up_link_ids
end

Instance Method Details

#to_htmlObject



18
19
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/almirah/doc_items/controlled_paragraph.rb', line 18

def to_html
  s = ''
  unless @@html_table_render_in_progress
    s += "<table class=\"controlled\">\n"
    s += "\t<thead> <th>#</th> <th></th> <th title=\"Up-links\">UL</th> <th title=\"Down-links\">DL</th> \
      <th title=\"Test Coverage\">COV</th> <th title=\"Decision Record\">DR</th> </thead>\n"
    @@html_table_render_in_progress = true # rubocop:disable Style/ClassVars
  end
  f_text = format_string(@text)
  s += "\t<tr>\n"
  s += "\t\t<td class=\"item_id\"> \
      <a name=\"#{@id}\" id=\"#{@id}\" href=\"##{@id}\" title=\"Paragraph ID\">#{@id}</a></td>\n"
  s += "\t\t<td class=\"item_text\">#{f_text}</td>\n"

  if @up_link_ids
    if @up_link_ids.length == 1
      if tmp = /^([a-zA-Z]+)-\d+/.match(@up_link_ids[0])
        up_link_doc_name = tmp[1].downcase
      end
      s += "\t\t<td class=\"item_id\">\
          <a href=\"#{parent_doc.specifications_path}#{up_link_doc_name}/#{up_link_doc_name}.html##{@up_link_ids[0]}\" \
          class=\"external\" title=\"Linked to\">#{@up_link_ids[0]}</a></td>\n"
    else
      s += "\t\t<td class=\"item_id\">"
      s += "<div id=\"UL_#{@id}\" style=\"display: block;\">"
      s += "<a  href=\"#\" onclick=\"upLink_OnClick(this.parentElement); return false;\" \
          class=\"external\" title=\"Number of up-links\">#{@up_link_ids.length}</a>"
      s += '</div>'
      s += "<div id=\"ULS_#{@id}\" style=\"display: none;\">"
      @up_link_ids.each do |lnk|
        if tmp = /^([a-zA-Z]+)-\d+/.match(lnk)
          up_link_doc_name = tmp[1].downcase
        end
        s += "\t\t\t<a href=\"#{parent_doc.specifications_path}#{up_link_doc_name}/#{up_link_doc_name}.html##{lnk}\" \
          class=\"external\" title=\"Linked to\">#{lnk}</a>\n<br>"
      end
      s += '</div>'
      s += "</td>\n"
    end
  else
    s += "\t\t<td class=\"item_id\"></td>\n"
  end

  if @down_links
    if tmp = /^([a-zA-Z]+)-\d+/.match(@down_links[0].id) # guessing that all the links refer to one document
      down_link_doc_name = tmp[1].downcase
    end
    if @down_links.length == 1
      s += "\t\t<td class=\"item_id\">\
          <a href=\"./../#{down_link_doc_name}/#{down_link_doc_name}.html##{@down_links[0].id}\" \
          class=\"external\" title=\"Referenced in\">#{@down_links[0].id}</a></td>\n"
    else
      s += "\t\t<td class=\"item_id\">"
      s += "<div id=\"DL_#{@id}\" style=\"display: block;\">"
      s += "<a  href=\"#\" onclick=\"downlink_OnClick(this.parentElement); return false;\" \
          class=\"external\" title=\"Number of references\">#{@down_links.length}</a>"
      s += '</div>'
      s += "<div id=\"DLS_#{@id}\" style=\"display: none;\">"
      @down_links.each do |lnk|
        s += "\t\t\t<a href=\"./../#{lnk.parent_doc.id}/#{lnk.parent_doc.id}.html##{lnk.id}\" \
          class=\"external\" title=\"Referenced in\">#{lnk.id}</a>\n<br>"
      end
      s += '</div>'
      s += "</td>\n"
    end
  else
    s += "\t\t<td class=\"item_id\"></td>\n"
  end

  if @coverage_links
    if tmp = /^(.+)[.]\d+/.match(@coverage_links[0].id)    # guessing that all the links refer to one document
      cov_link_doc_name = tmp[1].downcase
    end
    if @coverage_links.length == 1
      s += "\t\t<td class=\"item_id\">\
          <a href=\"./../../tests/protocols/#{cov_link_doc_name}/#{cov_link_doc_name}.html\" \
          class=\"external\" title=\"Number of verification steps\">#{@coverage_links[0].id}</a></td>\n"
    else
      s += "\t\t<td class=\"item_id\">"
      s += "<div id=\"COV_#{@id}\" style=\"display: block;\">"
      s += "<a  href=\"#\" onclick=\"coverageLink_OnClick(this.parentElement); return false;\" \
          class=\"external\" title=\"Number of verification steps\">#{@coverage_links.length}</a>"
      s += '</div>'
      s += "<div id=\"COVS_#{@id}\" style=\"display: none;\">"
      @coverage_links.each do |lnk|
        s += "\t\t\t<a href=\"./../../tests/protocols/#{lnk.parent_doc.id}/#{lnk.parent_doc.id}.html##{lnk.id}\" \
          class=\"external\" title=\"Covered in\">#{lnk.id}</a>\n<br>"
      end
      s += '</div>'
      s += "</td>\n"
    end
  else
    s += "\t\t<td class=\"item_id\"></td>\n"
  end

  if @decision_record_links
    if @decision_record_links.length == 1
      dr_doc = @decision_record_links[0].parent_doc
      s += "\t\t<td class=\"item_id\">\
          <a href=\"./../../decisions/#{dr_doc.html_rel_path}\" \
          class=\"external\" title=\"Decision Record\">#{dr_doc.id.upcase}</a></td>\n"
    else
      s += "\t\t<td class=\"item_id\">"
      s += "<div id=\"DR_#{@id}\" style=\"display: block;\">"
      s += "<a  href=\"#\" onclick=\"decisionLink_OnClick(this.parentElement); return false;\" \
          class=\"external\" title=\"Number of decision records\">#{@decision_record_links.length}</a>"
      s += '</div>'
      s += "<div id=\"DRS_#{@id}\" style=\"display: none;\">"
      @decision_record_links.each do |lnk|
        dr_doc = lnk.parent_doc
        s += "\t\t\t<a href=\"./../../decisions/#{dr_doc.html_rel_path}\" \
          class=\"external\" title=\"Referenced in\">#{dr_doc.id.upcase}</a>\n<br>"
      end
      s += '</div>'
      s += "</td>\n"
    end
  else
    s += "\t\t<td class=\"item_id\"></td>\n"
  end
  s += "\t</tr>\n"
  s
end