Class: ControlledTable

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

Direct Known Subclasses

ScopeTable

Constant Summary

Constants included from HtmlSafe

HtmlSafe::ALLOWED_URL_SCHEMES

Instance Attribute Summary collapse

Attributes inherited from DocItem

#parent_doc, #parent_heading

Instance Method Summary collapse

Methods inherited from DocItem

#get_url, #owner_document, #split_table_cells

Methods inherited from TextLine

#bold, #bold_and_italic, broken_links, #format_string, #inline_code, #italic, #link, link_registry, link_registry=, #literal_text, #owner_document, record_broken_link, reset_broken_links, #wiki_link

Methods included from HtmlSafe

#escape_attr, #escape_text, #safe_url

Methods inherited from TextLineBuilderContext

#bold, #bold_and_italic, #inline_code, #italic, #link, #literal_text, #wiki_link

Constructor Details

#initialize(doc, markdown_table) ⇒ ControlledTable

Returns a new instance of ControlledTable.



158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/almirah/doc_items/controlled_table.rb', line 158

def initialize(doc, markdown_table)
  @parent_doc = doc
  @parent_heading = doc.headings[-1]

  @column_names = markdown_table.column_names
  @is_separator_detected = markdown_table.is_separator_detected
  # copy and re-format existing rows
  @rows = []

  markdown_table.rows.each do |r|
    @rows.append(format_columns(r))
  end
end

Instance Attribute Details

#column_namesObject

Returns the value of attribute column_names.



156
157
158
# File 'lib/almirah/doc_items/controlled_table.rb', line 156

def column_names
  @column_names
end

#is_separator_detectedObject

Returns the value of attribute is_separator_detected.



156
157
158
# File 'lib/almirah/doc_items/controlled_table.rb', line 156

def is_separator_detected
  @is_separator_detected
end

#rowsObject

Returns the value of attribute rows.



156
157
158
# File 'lib/almirah/doc_items/controlled_table.rb', line 156

def rows
  @rows
end

Instance Method Details

#add_row(row) ⇒ Object



172
173
174
175
176
177
178
# File 'lib/almirah/doc_items/controlled_table.rb', line 172

def add_row(row)
  columns = split_table_cells(row)

  @rows.append(format_columns(columns))

  true
end

#format_columns(columns) ⇒ Object



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/almirah/doc_items/controlled_table.rb', line 180

def format_columns(columns)
  new_row = ControlledTableRow.new
  new_row.parent_doc = @parent_doc

  columns.each_with_index do |element, index|
    if index.zero? # it is expected that test step id is placed in the first columl

      col = TestStepNumberColumn.new element
      new_row.columns.append col
      new_row.id = "#{@parent_doc.id}.#{col.text}"
      col.row_id = new_row.id

    elsif index + 1 == columns.length # it is expected that a link is placed to the last column only

      col = TestStepReferenceColumn.new(new_row, element)
      new_row.columns << col
      # save uplink key but do not rewrite
      unless col.up_link_doc_ids.empty?
        col.up_link_doc_ids.each do |key, value|
          @parent_doc.up_link_docs[key] = value

          # save reference to the test step
          new_row.up_link_ids = col.up_link_ids
          @parent_doc.controlled_items.append new_row
        end
      end

    elsif (index + 2 == columns.length) && @parent_doc.instance_of?(Protocol) # test step result column applies only to Protocols

      col = TestStepResultColumn.new element
      new_row.columns.append col

    else
      col = RegualrColumn.new element
      new_row.columns.append col
    end
  end
  new_row
end

#to_htmlObject



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/almirah/doc_items/controlled_table.rb', line 220

def to_html
  s = ''
  if @@html_table_render_in_progress
    s += "</table>\n"
    @@html_table_render_in_progress = false
  end

  s += "<table class=\"markdown_table\">\n"
  s += "\t<thead>"

  @column_names.each do |h|
    s += " <th>#{h}</th>"
  end

  s += " </thead>\n"

  @rows.each do |row|
    s += row.to_html
  end

  s += "</table>\n"

  s
end