Class: Terminal::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/terminal-tableofhashes.rb

Class Method Summary collapse

Class Method Details

.from_hashes(array) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/terminal-tableofhashes.rb', line 6

def self.from_hashes(array)

  headings = Set.new
  array.each do |hash|
    hash.each do |k, v|
      headings << k
    end
  end

  rows = []
  array.each do |hash|
    row = []
    headings.each do |name|
      row << hash[name]
    end
    rows << row
  end

  new headings: headings, rows: rows
end