Class: NattyUI::Table::Row
- Inherits:
-
Object
- Object
- NattyUI::Table::Row
- Includes:
- Enumerable
- Defined in:
- lib/natty-ui/table.rb
Instance Method Summary collapse
-
#<<(text) ⇒ Row
Add a new cell to the row with given
text
. -
#[](index) ⇒ Cell?
Cell at given index.
-
#[]=(index, *args) ⇒ Cell
Created cell.
-
#add(*text, **attributes) ⇒ Cell
Add a new cell to the row with given
text
andattributes
. -
#count ⇒ Integer
Count of cells.
- #delete(cell) ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, **_) ⇒ Object (private)
147 148 149 150 151 152 |
# File 'lib/natty-ui/table.rb', line 147 def method_missing(name, *args, **_) return super unless name.end_with?('=') return super unless Cell::Attributes.public_method_defined?(name) @cells.each { _1.attributes.__send__(name, *args) } args[0] end |
Instance Method Details
#<<(text) ⇒ Row
Add a new cell to the row with given text
.
135 136 137 138 |
# File 'lib/natty-ui/table.rb', line 135 def <<(text) add(text) self end |
#[](index) ⇒ Cell?
Returns cell at given index.
112 |
# File 'lib/natty-ui/table.rb', line 112 def [](index) = @cells[index] |
#[]=(index, *args) ⇒ Cell
Returns created cell.
115 116 117 118 |
# File 'lib/natty-ui/table.rb', line 115 def []=(index, *args) @cells[index] = create_cell(args) @cells.map! { _1 || Cell.new } end |
#add(*text, **attributes) ⇒ Cell
Add a new cell to the row with given text
and attributes
.
122 123 124 125 126 |
# File 'lib/natty-ui/table.rb', line 122 def add(*text, **attributes) nc = Cell.new(*text, **attributes) @cells << nc block_given? ? yield(nc) : nc end |
#count ⇒ Integer
Returns count of cells.
107 |
# File 'lib/natty-ui/table.rb', line 107 def count = @cells.size |
#delete(cell) ⇒ Object
128 129 130 131 |
# File 'lib/natty-ui/table.rb', line 128 def delete(cell) cell.is_a?(Cell) ? @cells.delete(cell) : @cells.delete_at(cell) self end |
#each(&block) ⇒ Object
109 |
# File 'lib/natty-ui/table.rb', line 109 def each(&block) = @cells.each(&block) |
#empty? ⇒ Boolean
104 |
# File 'lib/natty-ui/table.rb', line 104 def empty? = @cells.empty? |