Class: NattyUI::Table::RowCollection
- Inherits:
-
Object
- Object
- NattyUI::Table::RowCollection
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/natty-ui/helper/table.rb
Overview
Ordered collection of Row objects belonging to a NattyUI::Table. Accessed via #rows.
Instance Attribute Summary collapse
-
#any? ⇒ Boolean
readonly
Wheter the collection contains at least one Row.
-
#empty? ⇒ Boolean
readonly
Wheter the collection is empty.
-
#none? ⇒ Boolean
readonly
Wheter the collection contains at no Row.
-
#size ⇒ Integer
readonly
Number of rows.
Instance Method Summary collapse
-
#[](index) ⇒ Row
Returns the row at
index, creating an empty row if none exists. -
#add(*texts, **attributes) {|row| ... } ⇒ Object, Row
Appends a new row, optionally pre-populated with text cells.
-
#add_text(*texts, **attributes) {|rows| ... } ⇒ Object, Array<Row>
Appends one new row per text value (each value becomes a single-cell row).
-
#at(index) ⇒ Row?
Returns the row at
index, ornilif it does not exist. -
#delete(index) ⇒ Boolean
Removes a row from the collection.
-
#each {|row| ... } ⇒ nil, Enumerator
Iterates over all non-nil rows.
-
#each_filled {|row| ... } ⇒ nil, Enumerator
Iterates over non-nil rows that contain at least one cell.
-
#insert(index, *texts, **attributes) {|row| ... } ⇒ Object, Row
Inserts a new row at the given index.
Instance Attribute Details
#any? ⇒ Boolean (readonly)
Wheter the collection contains at least one NattyUI::Table::Row.
|
|
# File 'lib/natty-ui/helper/table.rb', line 1008
|
#empty? ⇒ Boolean (readonly)
Wheter the collection is empty.
|
|
# File 'lib/natty-ui/helper/table.rb', line 1004
|
#none? ⇒ Boolean (readonly)
Wheter the collection contains at no NattyUI::Table::Row.
|
|
# File 'lib/natty-ui/helper/table.rb', line 1012
|
#size ⇒ Integer (readonly)
Number of rows.
|
|
# File 'lib/natty-ui/helper/table.rb', line 1000
|
Instance Method Details
#[](index) ⇒ Row
Returns the row at index, creating an empty row if none exists.
1032 |
# File 'lib/natty-ui/helper/table.rb', line 1032 def [](index) = @rows[index.to_int] ||= Row.new |
#add(*texts, **attributes) {|row| ... } ⇒ Object, Row
Appends a new row, optionally pre-populated with text cells.
1052 1053 1054 1055 1056 |
# File 'lib/natty-ui/helper/table.rb', line 1052 def add(*texts, **attributes) @rows << (row = Row.new(**attributes)) row.add_text(*texts) unless texts.empty? block_given? ? yield(row) : row end |
#add_text(*texts, **attributes) {|rows| ... } ⇒ Object, Array<Row>
Appends one new row per text value (each value becomes a single-cell row).
1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 |
# File 'lib/natty-ui/helper/table.rb', line 1092 def add_text(*texts, **attributes) @rows.concat( rows = texts.map! do |txt| row = Row.new(**attributes) row.add(*txt) row end ) block_given? ? yield(rows) : rows end |
#at(index) ⇒ Row?
Returns the row at index, or nil if it does not exist.
1023 |
# File 'lib/natty-ui/helper/table.rb', line 1023 def at(index) = @rows[index] |
#delete(index) ⇒ Boolean
Removes a row from the collection.
1108 1109 1110 1111 1112 1113 1114 1115 1116 |
# File 'lib/natty-ui/helper/table.rb', line 1108 def delete(index) row = if Row === index @rows.delete(index) else @rows.delete_at(index.to_int) end !row.freeze.nil? end |
#each {|row| ... } ⇒ nil, Enumerator
Iterates over all non-nil rows.
1127 1128 1129 1130 1131 |
# File 'lib/natty-ui/helper/table.rb', line 1127 def each return to_enum unless block_given? @rows.each { yield(it) if it } nil end |
#each_filled {|row| ... } ⇒ nil, Enumerator
Iterates over non-nil rows that contain at least one cell.
1138 1139 1140 1141 1142 |
# File 'lib/natty-ui/helper/table.rb', line 1138 def each_filled return to_enum(__method__) unless block_given? @rows.each { yield(it) if it&.any? } nil end |
#insert(index, *texts, **attributes) {|row| ... } ⇒ Object, Row
Inserts a new row at the given index.
1071 1072 1073 1074 1075 |
# File 'lib/natty-ui/helper/table.rb', line 1071 def insert(index, *texts, **attributes) @rows.insert(index.to_int, row = Row.new(**attributes)) row.add_text(*texts) unless texts.empty? block_given? ? yield(row) : row end |