14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/gritano/renderer.rb', line 14
def render_table(elements, *attributes)
if elements.count > 0
attributes_hash = {}
attributes.each do |a|
if a.respond_to?(:keys)
attributes_hash = attributes_hash.merge(a)
else
attributes_hash[a] = nil
end
end
table = Terminal::Table.new do |t|
t << attributes_hash.map { |key, value| key }
t << :separator
elements.each do |element|
row = []
attributes_hash.each do |attribute, params|
if params
row << element.send(attribute, params)
else
row << element.send(attribute)
end
end
t.add_row row
end
end
render_text table.to_s
else
render_text "there aren't #{elements.model.name.split(':')[-1].pluralize.downcase}", :warning
end
end
|