class TTY::Table::Transformation
A class for transforming table values
Used internally by {Table}
@api private
Public Class Methods
extract_tuples(args)
click to toggle source
Extract the header and row tuples from the value
@param [Array] args
@return [Object]
@api public
# File lib/tty/table/transformation.rb, line 18 def self.extract_tuples(args) rows = args.pop header = args.size.zero? ? nil : args.first if rows.first.is_a?(Hash) header, rows = group_header_and_rows(rows) end { header: header, rows: rows } end
group_header_and_rows(value)
click to toggle source
Group hash keys into header and values into rows
@param [Hash] value
@api public
# File lib/tty/table/transformation.rb, line 32 def self.group_header_and_rows(value) header = value.map(&:keys).flatten.uniq rows = value.reduce([]) { |arr, el| arr + el.values } [header, rows] end