table-formatter 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7628f5ac957aaa2c82a0b53caef164a514d885bf
4
- data.tar.gz: 8c0bd54beee4370c03c582698780873c969c997a
3
+ metadata.gz: 263c3df0bf2ecb043e77af1692a4db26909e31f7
4
+ data.tar.gz: 349fb9c3201bd0f7ec07f2285e33360e9f89f9ad
5
5
  SHA512:
6
- metadata.gz: fac7d908cc172148344a2587c95004204dda083e18dfbff6d12963359f5661c532b3b8cdaa1ae6fcb771ab69cba2dc9a63e8f281c6456b1c268fd64398e57ae1
7
- data.tar.gz: 73e804f2ef12913c96cd4041b112d2836367b878f2536a12a0ac134a513e3e98bc0f7dccce7a72bb4fa428e73fd2095bf6c20a1eb34e95c51b54f33d5c4ebfda
6
+ metadata.gz: 9feae5c5a65d0edf8dd1c83be56232e5af04ff945ac082fb5ed3d1cdb4af6f3f8b0915a8bca9cfb6f18edd41ea5260aa527db35438a3a07fb1e8e6ae058a07e8
7
+ data.tar.gz: 67bf8b8467a3923951a0d4705672c2800574eacaff86ae65a5be1eac6f78d7147626ada1832c4f6d6a5c3b4be570df7a9c88896f2b96cae1759a4d3d92e66bf9
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -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
- a = @source
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.clone, column_widths)
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
- col_widths[-1] -= col_widths.inject(&:+) - 80
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=80)
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
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-07-27 00:00:00.000000000 Z
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
- 2AM��TQ2����7EjlK���!q�GN��}c*�́Å��]T��Ί��}�������/���ŝ�N�IX؟+.�_���Z
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
+ _������rRT0��eEqy��&.��9_��P��To���Y�/��y��I�X���������ŤW���V���!�˫u14��_������Sܘ�Xoj���oC��� mbG�4��kzEP���V.��(�uRg����;��6 N�E|p���L:O��^C�.��O��PX3sA`�u�FV�R@���~/�_T�)�\eK����IG�K�l��KO��c9)18XT���������!��v���Z�G���