Class: RTables::Table::MonoTable
Instance Attribute Summary
#columns, #rows, #table_content, #table_header
Instance Method Summary
collapse
#add_column, #add_row, #column_exist?, #empty?, #initialize, #inspect, #raise_if_empty, #to_s
Instance Method Details
#max_content_length ⇒ Object
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/rtables/tables/monotable.rb', line 43
def max_content_length
max_len = 0
@table_content.each do |contents|
contents.each do |content|
len = content.length
max_len = len if max_len < len
end
end
max_len
end
|
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/rtables/tables/monotable.rb', line 56
def
max_len = 0
.each do |head|
len = head.length
max_len = len if max_len < len
end
max_len
end
|
#pad_content(content, clen) ⇒ Object
37
38
39
40
41
|
# File 'lib/rtables/tables/monotable.rb', line 37
def pad_content(content, clen)
spacing = clen - content.length
content + (' ' * spacing)
end
|
31
32
33
34
35
|
# File 'lib/rtables/tables/monotable.rb', line 31
def (, hlen)
spacing = hlen - .length
+ (' ' * spacing)
end
|
#render ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/rtables/tables/monotable.rb', line 4
def render
corner = '+'
line_horizontal = '-'
line_vertical = '|'
hlen =
clen = max_content_length
row_sep = "#{corner}#{line_horizontal * (hlen + 2)}#{corner}#{line_horizontal * (clen + 2)}#{corner}"
line_fmt = "#{line_vertical} %{header} #{line_vertical} %{content} #{line_vertical}"
lines = []
i = 0
lines << row_sep
@table_content.each do |contents|
contents.each do |content|
lines << line_fmt % { header: ([i], hlen), content: pad_content(content, clen) }
i += 1
end
i = 0
lines << row_sep
end
lines
end
|