Class: HtmlElement::Utils::TableManager

Inherits:
Object
  • Object
show all
Defined in:
lib/htmlelement/utils.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.assign_scope(table) ⇒ Object



84
85
86
# File 'lib/htmlelement/utils.rb', line 84

def self.assign_scope(table)
  @manager.assign_scope(table)
end

Instance Method Details

#assign_scope(table) ⇒ Object



101
102
103
104
105
106
107
108
# File 'lib/htmlelement/utils.rb', line 101

def assign_scope(table)
  scope = guess_header_scope(table)
  return table unless scope
  Utils.collect_elements_by_name(table, TH).each do |th|
    th[SCOPE] = scope
  end
  table
end

#guess_header_scope(table) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/htmlelement/utils.rb', line 88

def guess_header_scope(table)
  col_scope = COL
  row_scope = ROW

  cell_with_index(table) do |cell, i, j|
    return if span_set?(cell, ROWSPAN) or span_set?(cell, COLSPAN)
    col_scope = nil unless (i == 0) == (cell.tagname == TH)
    row_scope = nil unless (j == 0) == (cell.tagname == TH)
  end

  col_scope or row_scope
end