table-formatter 0.1.4 → 0.1.5
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/table-formatter.rb +19 -5
- metadata +4 -4
- metadata.gz.sig +1 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 263c3df0bf2ecb043e77af1692a4db26909e31f7
|
4
|
+
data.tar.gz: 349fb9c3201bd0f7ec07f2285e33360e9f89f9ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9feae5c5a65d0edf8dd1c83be56232e5af04ff945ac082fb5ed3d1cdb4af6f3f8b0915a8bca9cfb6f18edd41ea5260aa527db35438a3a07fb1e8e6ae058a07e8
|
7
|
+
data.tar.gz: 67bf8b8467a3923951a0d4705672c2800574eacaff86ae65a5be1eac6f78d7147626ada1832c4f6d6a5c3b4be570df7a9c88896f2b96cae1759a4d3d92e66bf9
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/table-formatter.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
#!/usr/bin/ruby
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# file: table-formatter.rb
|
2
4
|
|
3
5
|
class TableFormatter
|
4
6
|
|
@@ -10,19 +12,26 @@ class TableFormatter
|
|
10
12
|
@source = o[:source]
|
11
13
|
@labels = o[:labels]
|
12
14
|
@border = o[:border]
|
15
|
+
@maxwidth = 60
|
13
16
|
end
|
14
17
|
|
15
18
|
def display(width=nil)
|
16
|
-
|
19
|
+
|
20
|
+
#width ||= @maxwidth
|
21
|
+
@width = width
|
22
|
+
@maxwidth = width if width
|
23
|
+
a = @source.map {|x| x.map.to_a}.to_a
|
17
24
|
labels = @labels
|
18
25
|
column_widths = fetch_column_widths(a)
|
26
|
+
|
19
27
|
column_widths[-1] -= column_widths.inject(&:+) - width if width
|
20
28
|
|
21
|
-
records = format_rows(a
|
29
|
+
records = format_rows(a, column_widths)
|
22
30
|
|
23
31
|
div = (border == true ? '-' : ' ') * records[0].length + "\n"
|
24
32
|
label_buffer = ''
|
25
33
|
label_buffer = format_cols(labels, column_widths) + "\n" + div if labels
|
34
|
+
|
26
35
|
div + label_buffer + records.join("\n") + "\n" + div
|
27
36
|
|
28
37
|
end
|
@@ -36,6 +45,7 @@ class TableFormatter
|
|
36
45
|
end
|
37
46
|
|
38
47
|
def fetch_column_widths(a)
|
48
|
+
|
39
49
|
d = tabulate(a).map &:flatten
|
40
50
|
|
41
51
|
# find the maximum lengths
|
@@ -52,7 +62,11 @@ class TableFormatter
|
|
52
62
|
end
|
53
63
|
|
54
64
|
def format_rows(a, col_widths)
|
55
|
-
|
65
|
+
|
66
|
+
@width = col_widths.inject(&:+)
|
67
|
+
|
68
|
+
col_widths[-1] -= col_widths.inject(&:+) - @maxwidth
|
69
|
+
|
56
70
|
a.each_with_index do |x,i|
|
57
71
|
col_rows = wrap(x[-1], col_widths[-1]).split(/\n/)
|
58
72
|
if col_rows.length > 1 then
|
@@ -64,7 +78,7 @@ class TableFormatter
|
|
64
78
|
a.map {|row| format_cols(row, col_widths)}
|
65
79
|
end
|
66
80
|
|
67
|
-
def wrap(s, col
|
81
|
+
def wrap(s, col=@maxwidth)
|
68
82
|
s.gsub(/(.{1,#{col}})( +|$\n?)|(.{1,#{col}})/,
|
69
83
|
"\\1\\3\n")
|
70
84
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: table-formatter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -29,7 +29,7 @@ cert_chain:
|
|
29
29
|
87MJlDPDYzp5yHAWkCW+L5wNO0Z0kdkibE/RZ9yGgZ7rSPRUUBqwsxNfwvyVh8Gl
|
30
30
|
Ld73E8JjE0JpECfuT5M6ch5PUBtf1txl
|
31
31
|
-----END CERTIFICATE-----
|
32
|
-
date: 2013-
|
32
|
+
date: 2013-09-25 00:00:00.000000000 Z
|
33
33
|
dependencies: []
|
34
34
|
description:
|
35
35
|
email: james@r0bertson.co.uk
|
@@ -48,12 +48,12 @@ require_paths:
|
|
48
48
|
- lib
|
49
49
|
required_ruby_version: !ruby/object:Gem::Requirement
|
50
50
|
requirements:
|
51
|
-
- -
|
51
|
+
- - ">="
|
52
52
|
- !ruby/object:Gem::Version
|
53
53
|
version: '0'
|
54
54
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
55
|
requirements:
|
56
|
-
- -
|
56
|
+
- - ">="
|
57
57
|
- !ruby/object:Gem::Version
|
58
58
|
version: '0'
|
59
59
|
requirements: []
|
metadata.gz.sig
CHANGED
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
��:6ՊR��������������X�YT���]f)Fmẟ4$cu����:|���e�N~E��H����ju��>��=��%C9�2joԋp�㋅5Qo??�|o�ā&h�BE��k�����H�:���x+��g0�P�P�6��W�'3��l����!
|
1
|
+
_������r�RT0��e�Eqy��&.��9_��P��To���Y�/��y��I�X���������ŤW���V���!�˫u�14��_������Sܘ�Xoj���o�C���mbG�4��kzEP���V.��(�uRg����;��6 N�E|p���L:O��^C�.��O��PX�3sA`�u�FV�R@���~/�_T�)�\eK����IG�K�l��KO��c9)18XT���������!��v���Z�G���
|