rtables 1.0.1 → 1.1.0

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: f6ca63c3fa094725afe6a512242c42625b804c69
4
- data.tar.gz: a4007c9aa87978745c6bcb2c1cfc4a8d27cc6be7
3
+ metadata.gz: 909d7dd176344e9977b72be17cc61d9c3076df86
4
+ data.tar.gz: b3eabf41d60e1796afd24f7b681fe738cc4f9f47
5
5
  SHA512:
6
- metadata.gz: a8ab35eeb7fd374545eb59e5ed27b50023dc8c25d1f5a7ddda5e41b1e7f36344a70dac8c2dd5f5cbf337fcfb177b20b5529d1f242f16774eef7aebdf780cc765
7
- data.tar.gz: de32615674f18a08e305e811a32a4fb353dfe27e1d0ce239d07126497fa3f126be7265f1feb2005720ae8ab89e9f2ee609294162eadc7ca0a316efded96e753f
6
+ metadata.gz: 85bc77d535cc8ced5107b5adb144758e68575d5ae39f534a73df2da211c3efaf3a3c0914451725c0f7c49a95bdcdb6aff8c24be53ed783e5dbab52600583766e
7
+ data.tar.gz: 8d876f4dc27a86af7e448588ab5b63c27519e160d1841cbd4e205bc1f3cb1852aee9f325a82a3f9a7d36eec6bd8ca4fd4954b44df0a39242e16fe31469793c30
data/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2015 Jos 'Zarthus' Ahrens
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Jos 'Zarthus' Ahrens
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ # Monospace Table
2
+
3
+ Code:
4
+
5
+ ```ruby
6
+ require 'rtables'
7
+ table = RTables::Table::MonoTableAlt.new
8
+
9
+ table.add_column('Example')
10
+ table.add_column('Field')
11
+ table.add_row('First', 'This is an example text')
12
+ table.add_row('Small', 'Field')
13
+ table.add_row('Very Large Field', 'With a large amount of text on it.')
14
+
15
+ table.render
16
+ ```
17
+
18
+ Looks like (output from .ci/show_table_formats.rb):
19
+ ```
20
+ +--------------------------------------------------------------------------------------------------------------------+
21
+ | Name | Occupation | Voice Actor |
22
+ +--------------------------------------+--------------------------------------+--------------------------------------+
23
+ | Maxine Caulfield | Time Wizard | Serena de Mouroux |
24
+ | David N. Madsen | Head of Security at Blackwell Aca.. | Don McManus |
25
+ | Mark Jefferson | Professional Photographer, Teache.. | Derek Phillips |
26
+ +--------------------------------------------------------------------------------------------------------------------+
27
+ ```
28
+
29
+ ## Positives
30
+
31
+ - Easy to read
32
+ - Good for displaying two or three rows
33
+ - Good for displaying a lot of data.
34
+
35
+ ## Negatives
36
+
37
+ - Requires a Monospace font to render properly.
38
+ - Truncates lengthy data.
@@ -0,0 +1,39 @@
1
+ # Monospace Table
2
+
3
+ Code:
4
+
5
+ ```ruby
6
+ require 'rtables'
7
+ table = RTables::Table::UnicodeMonoTableAlt.new
8
+
9
+ table.add_column('Example')
10
+ table.add_column('Field')
11
+ table.add_row('First', 'This is an example text')
12
+ table.add_row('Small', 'Field')
13
+ table.add_row('Very Large Field', 'With a large amount of text on it.')
14
+
15
+ table.render
16
+ ```
17
+
18
+ Looks like (output from .ci/show_table_formats.rb):
19
+ ```
20
+ ┌──────────────────────────────────────┬──────────────────────────────────────┬──────────────────────────────────────┐
21
+ │ Name │ Occupation │ Voice Actor │
22
+ ├──────────────────────────────────────┼──────────────────────────────────────┼──────────────────────────────────────┤
23
+ │ Maxine Caulfield │ Time Wizard │ Serena de Mouroux │
24
+ │ David N. Madsen │ Head of Security at Blackwell Aca.. │ Don McManus │
25
+ │ Mark Jefferson │ Professional Photographer, Teache.. │ Derek Phillips │
26
+ └──────────────────────────────────────┴──────────────────────────────────────┴──────────────────────────────────────┘
27
+ ```
28
+
29
+ ## Positives
30
+
31
+ - Easy to read
32
+ - Good for displaying two or three rows
33
+ - Good for displaying a lot of data.
34
+
35
+ ## Negatives
36
+
37
+ - Requires a Monospace font to render properly.
38
+ - Will not function when charset is misconfigured, does not use basic ASCII characters.
39
+ - Truncates lengthy data
@@ -6,4 +6,6 @@ require 'rtables/tablebuilder'
6
6
  require 'rtables/tables/plaintable'
7
7
  require 'rtables/tables/simpletable'
8
8
  require 'rtables/tables/monotable'
9
+ require 'rtables/tables/monotablealt'
9
10
  require 'rtables/tables/unicodemonotable'
11
+ require 'rtables/tables/unicodemonotablealt'
@@ -1,68 +1,68 @@
1
- module RTables
2
- module Table
3
- class MonoTable < TableBuilder
4
- def render
5
- corner = '+'
6
- line_horizontal = '-'
7
- line_vertical = '|'
8
-
9
- hlen = max_header_length
10
- clen = max_content_length
11
-
12
- row_sep = "#{corner}#{line_horizontal * (hlen + 2)}#{corner}#{line_horizontal * (clen + 2)}#{corner}"
13
- line_fmt = "#{line_vertical} %{header} #{line_vertical} %{content} #{line_vertical}"
14
- lines = []
15
- i = 0
16
-
17
- lines << row_sep
18
- @table_content.each do |contents|
19
- contents.each do |content|
20
- lines << line_fmt % { header: pad_header(@table_header[i], hlen), content: pad_content(content, clen) }
21
- i += 1
22
- end
23
-
24
- i = 0
25
- lines << row_sep
26
- end
27
-
28
- lines
29
- end
30
-
31
- def pad_header(header, hlen)
32
- spacing = hlen - header.length
33
-
34
- header + (' ' * spacing)
35
- end
36
-
37
- def pad_content(content, clen)
38
- spacing = clen - content.length
39
-
40
- content + (' ' * spacing)
41
- end
42
-
43
- def max_content_length
44
- max_len = 0
45
-
46
- @table_content.each do |contents|
47
- contents.each do |content|
48
- len = content.length
49
- max_len = len if max_len < len
50
- end
51
- end
52
-
53
- max_len
54
- end
55
-
56
- def max_header_length
57
- max_len = 0
58
-
59
- @table_header.each do |head|
60
- len = head.length
61
- max_len = len if max_len < len
62
- end
63
-
64
- max_len
65
- end
66
- end
67
- end
68
- end
1
+ module RTables
2
+ module Table
3
+ class MonoTable < TableBuilder
4
+ def render
5
+ corner = '+'
6
+ line_horizontal = '-'
7
+ line_vertical = '|'
8
+
9
+ hlen = max_header_length
10
+ clen = max_content_length
11
+
12
+ row_sep = "#{corner}#{line_horizontal * (hlen + 2)}#{corner}#{line_horizontal * (clen + 2)}#{corner}"
13
+ line_fmt = "#{line_vertical} %{header} #{line_vertical} %{content} #{line_vertical}"
14
+ lines = []
15
+ i = 0
16
+
17
+ lines << row_sep
18
+ @table_content.each do |contents|
19
+ contents.each do |content|
20
+ lines << line_fmt % { header: pad_header(@table_header[i], hlen), content: pad_content(content, clen) }
21
+ i += 1
22
+ end
23
+
24
+ i = 0
25
+ lines << row_sep
26
+ end
27
+
28
+ lines
29
+ end
30
+
31
+ def pad_header(header, hlen)
32
+ spacing = hlen - header.length
33
+
34
+ header + (' ' * spacing)
35
+ end
36
+
37
+ def pad_content(content, clen)
38
+ spacing = clen - content.length
39
+
40
+ content + (' ' * spacing)
41
+ end
42
+
43
+ def max_content_length
44
+ max_len = 0
45
+
46
+ @table_content.each do |contents|
47
+ contents.each do |content|
48
+ len = content.length
49
+ max_len = len if max_len < len
50
+ end
51
+ end
52
+
53
+ max_len
54
+ end
55
+
56
+ def max_header_length
57
+ max_len = 0
58
+
59
+ @table_header.each do |head|
60
+ len = head.length
61
+ max_len = len if max_len < len
62
+ end
63
+
64
+ max_len
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,60 @@
1
+ module RTables
2
+ module Table
3
+ class MonoTableAlt < TableBuilder
4
+ def render
5
+ corner = '+'
6
+ line_horizontal = '-'
7
+ line_vertical = '|'
8
+
9
+ if @table_header.length > 4
10
+ column_size = 160 / @table_header.length
11
+ else
12
+ column_size = 70 - (@table_header.length * 10)
13
+ end
14
+
15
+ table = []
16
+ rowsep_item_tpl = "#{corner}#{((line_horizontal * (column_size - 2)) << corner) * @table_header.length}"
17
+ rowsep_tpl = "#{corner}#{line_horizontal * (rowsep_item_tpl.length - 2)}#{corner}"
18
+ item_tpl = "#{line_vertical} %s "
19
+
20
+ table << rowsep_tpl
21
+
22
+ item = ''
23
+ @table_header.each do |col|
24
+ item << pad(item_tpl % col, column_size - 3)
25
+ end
26
+ item << line_vertical
27
+ table << item
28
+ table << rowsep_item_tpl
29
+
30
+ @table_content.each do |content|
31
+ item = ''
32
+ content.each do |col|
33
+ item << pad(item_tpl % col, column_size - 3)
34
+ end
35
+
36
+ item << line_vertical
37
+ table << item
38
+ end
39
+
40
+ table << rowsep_tpl
41
+
42
+ table
43
+ end
44
+
45
+ def truncuate(s, len = 32, append = '..')
46
+ trunc_len = len - append.length - 1
47
+
48
+ return "#{s[0..trunc_len]}#{append}" if s.length > len
49
+ s
50
+ end
51
+
52
+ def pad(s, len = 32, append = '..')
53
+ s = truncuate(s, len, append)
54
+
55
+ return s if s.length > len
56
+ s << (' ' * (len - (s.length - 2)))
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,78 @@
1
+ module RTables
2
+ module Table
3
+ class UnicodeMonoTableAlt < TableBuilder
4
+ CORNER_POS_LTOP = '┌'
5
+ CORNER_POS_RTOP = '┐'
6
+ CORNER_POS_MTOP = '┬'
7
+
8
+ CORNER_POS_LMID = '├'
9
+ CORNER_POS_RMID = '┤'
10
+ CORNER_POS_MMID = '┼'
11
+
12
+ CORNER_POS_LBOT = '└'
13
+ CORNER_POS_RBOT = '┘'
14
+ CORNER_POS_MBOT = '┴'
15
+
16
+ def render
17
+ line_horizontal = '─'
18
+ line_vertical = '│'
19
+
20
+ if @table_header.length > 4
21
+ column_size = 160 / @table_header.length
22
+ else
23
+ column_size = 70 - (@table_header.length * 10)
24
+ end
25
+
26
+ row_sep_base = "#{(line_horizontal * (column_size - 2))}%{tchar}" * (@table_header.length)
27
+
28
+ # This needs to be smaller because without, we get one character added too many.
29
+ row_sep_base_small = row_sep_base[0..row_sep_base.length - 9]
30
+ row_sep_top = "#{CORNER_POS_LTOP}#{row_sep_base_small % { tchar: CORNER_POS_MTOP }}#{CORNER_POS_RTOP}"
31
+ row_sep_mid = "#{CORNER_POS_LMID}#{row_sep_base_small % { tchar: CORNER_POS_MMID }}#{CORNER_POS_RMID}"
32
+ row_sep_bot = "#{CORNER_POS_LBOT}#{row_sep_base_small % { tchar: CORNER_POS_MBOT }}#{CORNER_POS_RBOT}"
33
+
34
+ item_fmt = "#{line_vertical} %s"
35
+ table = []
36
+
37
+ table << row_sep_top
38
+
39
+ item = ''
40
+ @table_header.each do |col|
41
+ item << pad(item_fmt % col, column_size - 3)
42
+ end
43
+ item << line_vertical
44
+ table << item
45
+ table << row_sep_mid
46
+
47
+ @table_content.each do |contents|
48
+ item = ''
49
+
50
+ contents.each do |col|
51
+ item << pad(item_fmt % col, column_size - 3)
52
+ end
53
+
54
+ item << line_vertical
55
+ table << item
56
+ end
57
+
58
+ table << row_sep_bot
59
+
60
+ table
61
+ end
62
+
63
+ def truncuate(s, len = 32, append = '..')
64
+ trunc_len = len - append.length - 1
65
+
66
+ return "#{s[0..trunc_len]}#{append}" if s.length > len
67
+ s
68
+ end
69
+
70
+ def pad(s, len = 32, append = '..')
71
+ s = truncuate(s, len, append)
72
+
73
+ return s if s.length > len
74
+ s << (' ' * (len - (s.length - 2)))
75
+ end
76
+ end
77
+ end
78
+ end
@@ -1,3 +1,3 @@
1
1
  module RTables
2
- VERSION = '1.0.1'.freeze
2
+ VERSION = '1.1.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rtables
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jos Ahrens
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-08 00:00:00.000000000 Z
11
+ date: 2016-04-10 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: RTables allows you to generate your own table output in the least amount
14
14
  of code.
@@ -21,16 +21,20 @@ files:
21
21
  - README.md
22
22
  - docs/making_your_own_table.md
23
23
  - docs/tables/MonoTable.md
24
+ - docs/tables/MonoTableAlt.md
24
25
  - docs/tables/PlainTable.md
25
26
  - docs/tables/SimpleTable.md
26
27
  - docs/tables/UnicodeMonoTable.md
28
+ - docs/tables/UnicodeMonoTableAlt.md
27
29
  - docs/tables_in_2_minutes.md
28
30
  - lib/rtables.rb
29
31
  - lib/rtables/tablebuilder.rb
30
32
  - lib/rtables/tables/monotable.rb
33
+ - lib/rtables/tables/monotablealt.rb
31
34
  - lib/rtables/tables/plaintable.rb
32
35
  - lib/rtables/tables/simpletable.rb
33
36
  - lib/rtables/tables/unicodemonotable.rb
37
+ - lib/rtables/tables/unicodemonotablealt.rb
34
38
  - lib/rtables/version.rb
35
39
  homepage: https://github.com/zarthus/rtables
36
40
  licenses:
@@ -52,7 +56,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
56
  version: '0'
53
57
  requirements: []
54
58
  rubyforge_project:
55
- rubygems_version: 2.4.5
59
+ rubygems_version: 2.2.2
56
60
  signing_key:
57
61
  specification_version: 4
58
62
  summary: 'Ruby Tables: Generate tables fast and easy'