Class: TestStepReferenceColumn

Inherits:
ControlledTableColumn show all
Defined in:
lib/almirah/doc_items/controlled_table.rb

Overview

rubocop:disable Style/Documentation

Instance Attribute Summary collapse

Attributes inherited from ControlledTableColumn

#text

Instance Method Summary collapse

Methods inherited from TextLine

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

Methods inherited from TextLineBuilderContext

#bold, #bold_and_italic, #italic, #link

Constructor Details

#initialize(parent_row, text) ⇒ TestStepReferenceColumn

Returns a new instance of TestStepReferenceColumn.



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
# File 'lib/almirah/doc_items/controlled_table.rb', line 52

def initialize(parent_row, text)
  super(text)
  @up_link_ids = nil
  @up_link_doc_ids = {}
  @parent_row = parent_row

  up_links = nil

  # check if it contains the uplink (one or many)
  first_pos = text.length # for trailing commas
  tmp = text.scan(/(>\[(?>[^\[\]]|\g<0>)*\])/) # >[SRS-001], >[SYS-002]
  unless tmp.empty?
    up_links = []
    tmp.each do |ul|
      lnk = ul[0]
      # do not add links for the self document
      doc_id = /([a-zA-Z]+)-\d+/.match(lnk) # SRS
      up_links << lnk.upcase if doc_id # (doc_id) and (doc_id[1].downcase != doc.id.downcase)
      # try to find the real end of text
      pos = text.index(lnk)
      first_pos = pos if pos < first_pos
      # remove uplink from text
      text = text.split(lnk, 1).join('')
    end
    # remove trailing commas and spaces
    if text.length > first_pos
      first_pos -= 1
      text = text[0..first_pos].strip
    end
  end

  if up_links # rubocop:disable Style/GuardClause
    up_links.uniq! # remove duplicates
    # doc.items_with_uplinks_number += 1 # for statistics
    up_links.each do |ul|
      next unless tmp = />\[(\S*)\]$/.match(ul) # >[SRS-001]

      up_link_id = tmp[1]

      @up_link_ids ||= []

      @up_link_ids.append(up_link_id)

      if tmp = /^([a-zA-Z]+)-\d+/.match(up_link_id) # SRS
        @up_link_doc_ids[tmp[1].downcase.to_s] = tmp[1].downcase # multiple documents could be up-linked
      end
    end
  end
end

Instance Attribute Details

#parent_rowObject

Returns the value of attribute parent_row.



50
51
52
# File 'lib/almirah/doc_items/controlled_table.rb', line 50

def parent_row
  @parent_row
end

Returns the value of attribute up_link_doc_ids.



50
51
52
# File 'lib/almirah/doc_items/controlled_table.rb', line 50

def up_link_doc_ids
  @up_link_doc_ids
end

Returns the value of attribute up_link_ids.



50
51
52
# File 'lib/almirah/doc_items/controlled_table.rb', line 50

def up_link_ids
  @up_link_ids
end

Instance Method Details

#to_htmlObject

rubocop:disable Metrics/AbcSize,Metrics/MethodLength



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_items/controlled_table.rb', line 102

def to_html # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  s = ''
  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\" style=\"text-align: center;\">\
                  <a href=\"./../../../specifications/#{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\" style=\"text-align: center;\">"
      s += "<div id=\"COV_#{@parent_row.id}\" style=\"display: block;\">"
      s += "<a  href=\"#\" onclick=\"coverageLink_OnClick(this.parentElement); return false;\" \
                  class=\"external\" title=\"Number of verified items\">#{@up_link_ids.length}</a>"
      s += '</div>'
      s += "<div id=\"COVS_#{@parent_row.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=\"./../../../specifications/#{up_link_doc_name}/#{up_link_doc_name}.html##{lnk}\" \
                  class=\"external\" title=\"Verifies\">#{lnk}</a>\n<br>"
      end
      s += '</div>'
      s += "</td>\n"
    end
  else
    "\t\t<td style=\"text-align: center;\"></td>\n\r"
  end
end