class HtmlElement::Utils::TableManager
Constants
- CAPTION
- COLSPAN
- ROW
Public Class Methods
assign_scope(table)
click to toggle source
# File lib/htmlelement/utils.rb, line 84 def self.assign_scope(table) @manager.assign_scope(table) end
Public Instance Methods
assign_scope(table)
click to toggle source
# 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)
click to toggle source
# 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
Private Instance Methods
cell_with_index(table) { |cell, i, j| ... }
click to toggle source
# File lib/htmlelement/utils.rb, line 112 def cell_with_index(table) children_except_caption(table).each_with_index do |tr, i| tr.children.each_with_index do |cell, j| yield cell, i, j end end end
children_except_caption(table)
click to toggle source
# File lib/htmlelement/utils.rb, line 120 def children_except_caption(table) children = table.children children[0].tagname == CAPTION ? children[1..-1] : children end
span_set?(cell, span)
click to toggle source
# File lib/htmlelement/utils.rb, line 125 def span_set?(cell, span) cell[span] && cell[span] > 1 end