Class: Umbreo::Helpers::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/umbreo/helpers/table.rb

Class Method Summary collapse

Class Method Details

.show_table(data, title, headings = []) ⇒ Object



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
# File 'lib/umbreo/helpers/table.rb', line 17

def self.show_table(data, title, headings = [])
	if data.present?
       rows  = []
       data.each do |data|

       	sub_arr = data.is_a?(Array) ? data : data.to_a
       	cell    = []

         if data.is_a? Array
           sub_arr.each do |arr|
             cell << arr
           end
         else
         	sub_arr.each do |arr|
         		cell << arr[1]
         	end
         end

       	rows << cell
       end

       table = Terminal::Table.new :title => title, :headings => headings, :rows => rows
       puts table
	end
end

.table_callback_retrieve_data(data, title) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
# File 'lib/umbreo/helpers/table.rb', line 5

def self.table_callback_retrieve_data(data, title)
	if data.present?
       rows  = []
       data.each do |data|
         data = data['name'].present? ? data['name'] : data
         rows << [ data ] 
       end
       table = Terminal::Table.new :title => title, :headings => ['Name'], :rows => rows
       puts table
	end
end