Class: NattyUI::Table

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#columnsColumnsCollection (readonly)

Returns table columns.

Returns:



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.

Returns:

  • (Row)

    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_countInteger

Returns count of columns.

Returns:

  • (Integer)

    count of columns



199
# File 'lib/natty-ui/table.rb', line 199

def column_count = @rows.empty? ? 0 : @rows.max_by(&:count).count

#countInteger

Returns count of rows.

Returns:

  • (Integer)

    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

Returns:

  • (Boolean)


193
# File 'lib/natty-ui/table.rb', line 193

def empty? = @rows.empty?