Class: TTY::Table::Transformation
- Inherits:
-
Object
- Object
- TTY::Table::Transformation
- Defined in:
- lib/tty/table/transformation.rb
Overview
A class for transforming table values
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
16 17 18 19 20 21 22 23 |
# File 'lib/tty/table/transformation.rb', line 16 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
30 31 32 33 34 |
# File 'lib/tty/table/transformation.rb', line 30 def self.group_header_and_rows(value) header = value.map(&:keys).flatten.uniq rows = value.inject([]) { |arr, el| arr + el.values } [header, rows] end |