Class: Tabulo::Row
Instance Attribute Summary collapse
- #source ⇒ Object readonly
Instance Method Summary collapse
Instance Attribute Details
#source ⇒ Object (readonly)
Returns the element of the Table's underlying enumerable to which this Tabulo::Row corresponds.
7 8 9 |
# File 'lib/tabulo/row.rb', line 7 def source @source end |
Instance Method Details
#each ⇒ Object
Calls the given block once for each Cell in the Tabulo::Row, passing that Cell as parameter.
26 27 28 29 30 |
# File 'lib/tabulo/row.rb', line 26 def each @table.column_registry.each_with_index do |(_, column), column_index| yield column.body_cell(@source, row_index: @index, column_index: column_index) end end |
#to_h ⇒ Object
Returns a Hash representation of the Tabulo::Row, with column labels acting as keys and the Cells the values.
45 46 47 48 49 |
# File 'lib/tabulo/row.rb', line 45 def to_h @table.column_registry.map.with_index do |(label, column), column_index| [label, column.body_cell(@source, row_index: @index, column_index: column_index)] end.to_h end |
#to_s ⇒ Object
Returns a String being an "ASCII" graphical representation of the Tabulo::Row, including any column headers or row divider that appear just above it in the Table (depending on where this Row is in the Table, and how the Table was configured with respect to header frequency and divider frequency).
36 37 38 39 40 41 42 |
# File 'lib/tabulo/row.rb', line 36 def to_s if @table.column_registry.any? @table.formatted_body_row(@source, divider: @divider, header: @header, index: @index) else "" end end |