colorful_tables 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/colorful_tables/version.rb +1 -1
- data/lib/colorful_tables.rb +3 -0
- data/lib/column.rb +1 -1
- data/lib/misc.rb +11 -0
- data/lib/table.rb +9 -5
- metadata +5 -4
data/lib/colorful_tables.rb
CHANGED
data/lib/column.rb
CHANGED
@@ -22,7 +22,7 @@ module ColorfulTables
|
|
22
22
|
def calculate_width
|
23
23
|
# We have to add the header in the calculation
|
24
24
|
data_and_header = self.data + [self.header]
|
25
|
-
data_and_header.map { |
|
25
|
+
data_and_header.map { |cell| ColorfulTables.truncate_if_float(cell).to_s.length }.max
|
26
26
|
end
|
27
27
|
|
28
28
|
end
|
data/lib/misc.rb
ADDED
data/lib/table.rb
CHANGED
@@ -55,15 +55,19 @@ module ColorfulTables
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def format(row_elements)
|
58
|
-
row_elements.inject_with_index(@border_chars[:vertical])
|
58
|
+
output = row_elements.inject_with_index(@border_chars[:vertical]) do |s, element, index|
|
59
|
+
value = ColorfulTables.truncate_if_float(element)
|
60
|
+
color = @columns_options[index][:data_color].is_a?(Proc) ? @columns_options[index][:data_color].call(value) : @columns_options[index][:data_color]
|
61
|
+
s += " #{value.to_s.rjust(@columns_width[index]).colorize(color)} #{@border_chars[:vertical]}"
|
62
|
+
end
|
63
|
+
output + "\n"
|
59
64
|
end
|
60
65
|
|
61
66
|
def calculate_border_chars
|
62
67
|
color = @options[:border_color]
|
63
|
-
{:vertical => '|'.colorize(color),
|
64
|
-
|
65
|
-
|
66
|
-
}
|
68
|
+
{ :vertical => '|'.colorize(color),
|
69
|
+
:horizontal => '-'.colorize(color),
|
70
|
+
:cross => '+'.colorize(color) }
|
67
71
|
end
|
68
72
|
|
69
73
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: colorful_tables
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 3
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.3.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Javier Vidal
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-10-
|
18
|
+
date: 2011-10-11 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- lib/column.rb
|
52
52
|
- lib/enumerable.rb
|
53
53
|
- lib/errors.rb
|
54
|
+
- lib/misc.rb
|
54
55
|
- lib/object.rb
|
55
56
|
- lib/table.rb
|
56
57
|
has_rdoc: true
|