Class: NattyUI::Table
- Inherits:
-
Object
- Object
- NattyUI::Table
- Includes:
- Enumerable
- Defined in:
- lib/natty-ui/table.rb
Overview
TODO:
This chapter needs more documentation.
Collection of rows and columns used by Features#table.
Defined Under Namespace
Classes: Attributes, Cell, Column, ColumnsCollection, Row
Instance Attribute Summary collapse
-
#columns ⇒ ColumnsCollection
readonly
Table columns.
Instance Method Summary collapse
- #[](row_index, column_index = nil) ⇒ Object
-
#add(*text, **attributes) ⇒ Row
Created row.
-
#column_count ⇒ Integer
Count of columns.
-
#count ⇒ Integer
Count of rows.
- #delete(row) ⇒ Object
- #each(&block) ⇒ Object
- #each_cell_of(column_index) ⇒ Object
- #empty? ⇒ Boolean
Instance Attribute Details
#columns ⇒ ColumnsCollection (readonly)
Returns table columns.
191 192 193 |
# File 'lib/natty-ui/table.rb', line 191 def columns @columns end |
Instance Method Details
#[](row_index, column_index = nil) ⇒ Object
203 204 205 206 |
# File 'lib/natty-ui/table.rb', line 203 def [](row_index, column_index = nil) row = @rows[row_index] or return column_index ? row[column_index] : row end |
#add(*text, **attributes) ⇒ Row
Returns created row.
209 210 211 212 213 214 |
# File 'lib/natty-ui/table.rb', line 209 def add(*text, **attributes) nr = Row.new @rows << nr text.each { nr.add(_1, **attributes) } block_given? ? yield(nr) : nr end |
#column_count ⇒ Integer
Returns count of columns.
199 |
# File 'lib/natty-ui/table.rb', line 199 def column_count = @rows.empty? ? 0 : @rows.max_by(&:count).count |
#count ⇒ Integer
Returns count of rows.
196 |
# File 'lib/natty-ui/table.rb', line 196 def count = @rows.size |
#delete(row) ⇒ Object
216 217 218 |
# File 'lib/natty-ui/table.rb', line 216 def delete(row) row.is_a?(Row) ? @rows.delete(row) : @rows.delete_at(row) end |
#each(&block) ⇒ Object
201 |
# File 'lib/natty-ui/table.rb', line 201 def each(&block) = @rows.each(&block) |
#each_cell_of(column_index) ⇒ Object
220 221 222 223 224 225 |
# File 'lib/natty-ui/table.rb', line 220 def each_cell_of(column_index) return to_enum(__method__, column_index) unless block_given? return if (column_index = column_index.to_i) >= column_count @rows.each { yield(_1[column_index]) } nil end |
#empty? ⇒ Boolean
193 |
# File 'lib/natty-ui/table.rb', line 193 def empty? = @rows.empty? |