class Cucumber::MultilineArgument::DataTable::DiffMatrices

def pad_and_match

Pads two cell matrices to same column width and matches columns according to header value.
def pad_and_match
  cols = cell_matrix.transpose
  unmatched_cols = other_table_cell_matrix.transpose
  header_values = cols.map(&:first)
  matched_cols = []
  header_values.each_with_index do |v, i|
    mapped_index = unmatched_cols.index { |unmapped_col| unmapped_col.first == v }
    if mapped_index
      matched_cols << unmatched_cols.delete_at(mapped_index)
    else
      mark_as_missing(cols[i])
      empty_col = ensure_2d(other_table_cell_matrix).collect { SurplusCell.new(nil, self, -1) }
      empty_col.first.value = v
      matched_cols << empty_col
    end
  end
  unmatched_cols.each do
    empty_col = cell_matrix.collect { SurplusCell.new(nil, self, -1) }
    cols << empty_col
  end
  self.cell_matrix = ensure_2d(cols.transpose)
  self.other_table_cell_matrix = ensure_2d((matched_cols + unmatched_cols).transpose)
end