57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/applebot/shell.rb', line 57
def table(data)
table = nil
if data.first && data.first[-1].is_a?(Hash)
headings = ['key'] + data.first[-1].keys
rows = data.to_a.map { |key_and_value|
row = []
headings.each do |heading|
if heading == 'key'
row << key_and_value[0]
else
row << key_and_value[1][heading]
end
end
row
}
table = Terminal::Table.new headings: headings, rows: rows
else
table = Terminal::Table.new rows: data.to_a
end
table
end
|