class Tabulo::Row
Attributes
source[R]
@return the element of the {Table}'s underlying enumerable to which this {Row} corresponds
Public Class Methods
new(table, source, divider:, header:, index:)
click to toggle source
@!visibility private
# File lib/tabulo/row.rb, line 10 def initialize(table, source, divider:, header:, index:) @table = table @source = source @divider = divider @header = header @index = index end
Public Instance Methods
each() { |body_cell(source, row_index: index, column_index: column_index)| ... }
click to toggle source
Calls the given block once for each {Cell} in the {Row}, passing that {Cell} as parameter.
@example
table = Tabulo::Table.new([1, 10], columns: %i(itself even?)) row = table.first row.each do |cell| puts cell.value # => 1, => false end
# 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()
click to toggle source
@return a Hash representation of the {Row}, with column labels acting as keys and the {Cell}s the values.
# 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()
click to toggle source
@return a String being an “ASCII” graphical representation of the {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).
# 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