Method: Slither::Section#format

Defined in:
lib/slither/section.rb

#format(data) ⇒ Object

Format a data Hash using columns width.

  • Data - hash, based on columns definitions content.

Ex: Having the next 2 columns .column(:id, 5) && .column(:name, 10)

we pass the data hash data = { id: 3, name: "Ryan" }
the result is the content of the hash based on the columns width:

format(data)

=> "    3      Ryan"

51
52
53
54
55
56
57
58
59
60
# File 'lib/slither/section.rb', line 51

def format(data)
  # raise( ColumnMismatchError,
  #   "The '#{@name}' section has #{@columns.size} column(s) defined, but there are #{data.size} column(s) provided in the data."
  # ) unless @columns.size == data.size
  row = ''
  @columns.each do |column|
    row += column.format(data[column.name])
  end
  row
end