Class: ControlledTable

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

Overview

rubocop:disable Style/Documentation

Instance Attribute Summary collapse

Attributes inherited from DocItem

#parent_doc, #parent_heading

Instance Method Summary collapse

Methods inherited from DocItem

#get_url

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(doc, markdown_table) ⇒ ControlledTable

rubocop:disable Lint/MissingSuper



138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/almirah/doc_items/controlled_table.rb', line 138

def initialize(doc, markdown_table) # rubocop:disable Lint/MissingSuper
  @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.



136
137
138
# File 'lib/almirah/doc_items/controlled_table.rb', line 136

def column_names
  @column_names
end

#is_separator_detectedObject

Returns the value of attribute is_separator_detected.



136
137
138
# File 'lib/almirah/doc_items/controlled_table.rb', line 136

def is_separator_detected
  @is_separator_detected
end

#rowsObject

Returns the value of attribute rows.



136
137
138
# File 'lib/almirah/doc_items/controlled_table.rb', line 136

def rows
  @rows
end

Instance Method Details

#add_row(row) ⇒ Object



152
153
154
155
156
157
158
# File 'lib/almirah/doc_items/controlled_table.rb', line 152

def add_row(row)
  columns = row.split('|')

  @rows.append(format_columns(columns))

  true
end

#format_columns(columns) ⇒ Object

rubocop:disable Metrics/AbcSize,Metrics/MethodLength



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/almirah/doc_items/controlled_table.rb', line 160

def format_columns(columns) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
  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 # it is expected that test step result is placed to the pre-last column only

      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

rubocop:disable Metrics/MethodLength



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# File 'lib/almirah/doc_items/controlled_table.rb', line 200

def to_html # rubocop:disable Metrics/MethodLength
  s = ''
  if @@html_table_render_in_progress
    s += "</table>\n"
    @@html_table_render_in_progress = false # rubocop:disable Style/ClassVars
  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