Class: TTY::Table::Transformation Private
- Inherits:
-
Object
- Object
- TTY::Table::Transformation
- Defined in:
- lib/tty/table/transformation.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A class for transforming table values
Used internally by TTY::Table
Class Method Summary collapse
-
.extract_tuples(args) ⇒ Object
Extract the header and row tuples from the value.
-
.group_header_and_rows(value) ⇒ Object
Group hash keys into header and values into rows.
Class Method Details
.extract_tuples(args) ⇒ Object
Extract the header and row tuples from the value
18 19 20 21 22 23 24 25 |
# 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) ⇒ Object
Group hash keys into header and values into rows
32 33 34 35 36 |
# 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 |