Class: ControlledTable

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

Instance Attribute Summary collapse

Attributes inherited from DocItem

#parent_doc

Instance Method Summary collapse

Methods inherited from TextLine

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

Constructor Details

#initialize(markdown_table, parent_doc) ⇒ ControlledTable

Returns a new instance of ControlledTable.



91
92
93
94
95
96
97
98
99
100
# File 'lib/almirah/doc_items/controlled_table.rb', line 91

def initialize(markdown_table, parent_doc)
    @parent_doc = parent_doc
    @column_names = markdown_table.column_names
    # copy and re-format existing rows
    @rows = Array.new

    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.



88
89
90
# File 'lib/almirah/doc_items/controlled_table.rb', line 88

def column_names
  @column_names
end

#rowsObject

Returns the value of attribute rows.



89
90
91
# File 'lib/almirah/doc_items/controlled_table.rb', line 89

def rows
  @rows
end

Instance Method Details

#addRow(row) ⇒ Object



102
103
104
105
106
107
108
109
# File 'lib/almirah/doc_items/controlled_table.rb', line 102

def addRow(row)

    columns = row.split('|')

    @rows.append(format_columns(columns))

    return true
end

#format_columns(columns) ⇒ Object



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
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/almirah/doc_items/controlled_table.rb', line 111

def format_columns(columns)

    new_row = ControlledTableRow.new
    new_row.parent_doc = @parent_doc

    columns.each_with_index do | element, index |

        if index == 0 # 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 element
            new_row.columns.append col
            # save uplink key but do not rewrite
            if col.up_link_doc_id != nil 
                
                @parent_doc.up_link_doc_id[ col.up_link_doc_id.to_s ] = col.up_link_doc_id

                # save reference to the test step
                new_row.up_link = col.up_link
                @parent_doc.controlled_items.append new_row
            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
    return new_row
end

#to_htmlObject



152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/almirah/doc_items/controlled_table.rb', line 152

def to_html
    s = ''
    if @@htmlTableRenderInProgress
        s += "</table>\n"
        @@htmlTableRenderInProgress = 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"

    return s
end