Class: NattyUI::Table::ColumnCollection
- Inherits:
-
Object
- Object
- NattyUI::Table::ColumnCollection
- Includes:
- Enumerable
- Defined in:
- lib/natty-ui/helper/table.rb
Overview
Collection of Column objects for a NattyUI::Table.
Accessed via #columns. Columns are created on demand; accessing a column index that has no data still returns a valid Column object whose cells reference the underlying table rows.
Instance Method Summary collapse
-
#[](index) ⇒ Column?
Returns the column at
index, ornilif the index is beyond the table width. -
#add(*texts, **attributes) {|column| ... } ⇒ Object, Column
Appends a new column (adds cells to each existing row) and returns it.
-
#at(index) ⇒ Column?
Returns the column at
index, ornilif no cells exist at that index. -
#each {|column| ... } ⇒ nil, Enumerator
Iterates over columns that contain at least one non-nil cell.
Instance Method Details
#[](index) ⇒ Column?
Returns the column at index, or nil if the index is beyond the
table width.
1191 1192 1193 1194 |
# File 'lib/natty-ui/helper/table.rb', line 1191 def [](index) index = index.to_int @columns[index] if index < max end |
#add(*texts, **attributes) {|column| ... } ⇒ Object, Column
Appends a new column (adds cells to each existing row) and returns it.
1211 1212 1213 1214 1215 1216 |
# File 'lib/natty-ui/helper/table.rb', line 1211 def add(*texts, **attributes) col = @columns[max] col.attributes.assign(attributes) unless attributes.empty? col.fill_text(0, *texts) block_given? ? yield(col) : col end |
#at(index) ⇒ Column?
Returns the column at index, or nil if no cells exist at that index.
1182 1183 1184 |
# File 'lib/natty-ui/helper/table.rb', line 1182 def at(index) @columns.key?(index = index.to_int) and @columns[index] end |
#each {|column| ... } ⇒ nil, Enumerator
Iterates over columns that contain at least one non-nil cell.
1227 1228 1229 1230 1231 1232 1233 |
# File 'lib/natty-ui/helper/table.rb', line 1227 def each return to_enum unless block_given? max.times do |index| @table.rows.any? { it.at(index) } or next yield(@columns[index]) end end |