class Ezframe::Ht::Table
テーブルを生成するためのクラス @matrix … テーブルの内容となる二次元配列 @header … テーブルの先頭に付ける項目名の配列 @class_a … <table><tr><td>の各ノードにそれぞれ設定したいclass属性を配列として定義
Attributes
class_a[RW]
header[RW]
matrix[RW]
Public Class Methods
new(matrix = nil)
click to toggle source
# File lib/ezframe/ht.rb, line 155 def initialize(matrix = nil) set(matrix) if matrix @matrix ||= [] end
Public Instance Methods
add_row(row)
click to toggle source
# File lib/ezframe/ht.rb, line 164 def add_row(row) @matrix.push(row) end
set(matrix)
click to toggle source
# File lib/ezframe/ht.rb, line 160 def set(matrix) @matrix = matrix end
to_h()
click to toggle source
# File lib/ezframe/ht.rb, line 168 def to_h table_class, tr_class, td_class = @class_a max_col = 0 @matrix.each { |row| max_col = row.length if max_col < row.length } tr_a = @matrix.map do |row| add_attr = nil add_attr = { colspan: max_col - row.length + 1 } if row.length < max_col td_a = row.map do |v| td = Ht.td(child: v) td.add_class(td_class) if td_class td end td_a[0].update(add_attr) if add_attr tr = Ht.tr(class: tr_class, child: td_a) tr.add_class(tr_class) if tr_class tr end tr_a.unshift( Ht.thead(child: Ht.tr(child: @header.map {|v| Ht.th(child: v) }) )) if @header tb = Ht.table(child: tr_a) tb.add_class(table_class) if table_class tb end