table-formatter 0.4.1 → 0.4.2

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: 03a4c83a58f33e614548562f0343f2fe5274718b
4
- data.tar.gz: 5f92da132883f92fb39d3397a6a975fd28fd7a88
3
+ metadata.gz: 9d81e18e59664d73f4f1e940937bb7d722095997
4
+ data.tar.gz: 120fff26f7a93e8214aca2bce747a0cde83e9653
5
5
  SHA512:
6
- metadata.gz: 05d9086ee08f11fbbea30d348d1e444f24df3ced4586ff34acdd951693e99ee653f617028548b0d5ae96dd2821e3f99a69a024035d55be8dbdb50ac83f3608ff
7
- data.tar.gz: 1ab0a258255809694fb233386da7c5222f30956da2544c27a819a7a4030ad56c6a289f413dd0d4017958a4ed18bd0bded992620c404490663db6ac15144cbe50
6
+ metadata.gz: beea41dbb8cf175cf127e6126c7579628a35933a84fa01e3fb7676a4c682ef10ed9ae3f9f0a0b00f55dd3ebd30e0f71c5c7ac692e5edc622099a0e9a8633b3fc
7
+ data.tar.gz: f9547ef046aa0dc183818d8fa3583d041784a161e8ed93681e19a8dada5ce5fbc9f8e8d89bee3292dc56929cd0344f9781337ad3d4e3db9dd6bb94f6f3ba5e2c
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -7,7 +7,7 @@ class TableFormatter
7
7
  attr_accessor :source, :labels, :border, :divider, :markdown, :col_justify
8
8
 
9
9
  def initialize(source: nil, labels: nil, border: true, wrap: true,
10
- divider: nil, markdown: false)
10
+ divider: nil, markdown: false, innermarkdown: false)
11
11
 
12
12
  super()
13
13
  @source = source
@@ -17,6 +17,7 @@ class TableFormatter
17
17
  @divider = divider
18
18
  @maxwidth = 60
19
19
  @markdown = markdown
20
+ @innermarkdown = innermarkdown
20
21
 
21
22
  end
22
23
 
@@ -87,9 +88,78 @@ class TableFormatter
87
88
 
88
89
 
89
90
  private
90
-
91
+
91
92
  def display_markdown(a, fields)
92
93
 
94
+ print_row = -> (row, widths) do
95
+ '| ' + row.map\
96
+ .with_index {|y,i| y.to_s.ljust(widths[i])}.join(' | ') + " |\n"
97
+ end
98
+
99
+ print_thline = -> (row, widths) do
100
+ '|:' + row.map\
101
+ .with_index {|y,i| y.to_s.ljust(widths[i])}.join('|:') + "|\n"
102
+ end
103
+
104
+ print_rows = -> (rows, widths) do
105
+ rows.map {|x| print_row.call(x,widths)}.join
106
+ end
107
+
108
+
109
+ raw_vals = a
110
+
111
+ # create Markdown hyperlinks for any URLs
112
+
113
+ vals = raw_vals.map do |row|
114
+
115
+ row.map do |col|
116
+
117
+ found_match = col.match(/^https?:\/\/([^\/]+)(.*)/)
118
+
119
+ r = if found_match then
120
+
121
+ domain, path = found_match.captures
122
+
123
+ a = domain.split('.')
124
+ a.shift if a.length > 2
125
+ url_title = (a.join('.') + path)[0..39] + '...'
126
+
127
+ "[%s](%s)" % [url_title, col]
128
+
129
+ else
130
+
131
+ if @innermarkdown then
132
+ "{::nomarkdown}" +
133
+ RDiscount.new(col).to_html.strip.gsub("\n",'') + "{:/}"
134
+ else
135
+
136
+ col
137
+
138
+ end
139
+
140
+ end
141
+
142
+ r
143
+ end
144
+ end
145
+
146
+ widths = ([(fields + ['']).take(a.first.length)] +
147
+ vals).transpose.map{|x| x.max_by(&:length).length}
148
+
149
+ th = if @labels then
150
+ print_row.call(@labels, widths)
151
+ else
152
+ ''
153
+ end
154
+
155
+ th_line = print_thline.call widths.map {|x| '-' * (x+1)}, widths
156
+ tb = print_rows.call(vals, widths)
157
+
158
+ table = th + th_line + tb
159
+ end
160
+
161
+ def display_markdown2(a, fields)
162
+
93
163
  print_row = -> (row, widths) do
94
164
 
95
165
  '| ' + row.map.with_index do |y,i|
@@ -124,6 +194,7 @@ class TableFormatter
124
194
 
125
195
  # find the maximum lengths
126
196
  d.map{|x| x.max_by(&:length).length}
197
+
127
198
  end
128
199
 
129
200
  def format_cols(row, col_widths, bar='')
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.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -12,26 +12,26 @@ cert_chain:
12
12
  -----BEGIN CERTIFICATE-----
13
13
  MIIDljCCAn6gAwIBAgIBATANBgkqhkiG9w0BAQUFADBIMRIwEAYDVQQDDAlnZW1t
14
14
  YXN0ZXIxHjAcBgoJkiaJk/IsZAEZFg5qYW1lc3JvYmVydHNvbjESMBAGCgmSJomT
15
- 8ixkARkWAmV1MB4XDTE2MDcxMjE3MDUyNloXDTE3MDcxMjE3MDUyNlowSDESMBAG
15
+ 8ixkARkWAmV1MB4XDTE3MDkwNjExNTY0OFoXDTE4MDkwNjExNTY0OFowSDESMBAG
16
16
  A1UEAwwJZ2VtbWFzdGVyMR4wHAYKCZImiZPyLGQBGRYOamFtZXNyb2JlcnRzb24x
17
17
  EjAQBgoJkiaJk/IsZAEZFgJldTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
18
- ggEBAMHvCAviVO+ls3i2lZPbHl982EOKMXIgrIYRWJx/oxjwgdXexyqgfbS7T+fc
19
- GxiGxxTBsBv1FU9but4o2QrTiHnk8dqL36lmk6bT3kID+WHg+zOc4RJ5QRCsucCw
20
- u7H4C2B+WN/Txy/jJMTJNTz+/5W2kj5oY/2chjl370FvyRZRLQAdjKcrutJzkApQ
21
- PtPkqrRBN3d7WZghsRR59OSolUbnkvJ/smFMwwjL8NACq+MTeHZEWoERgJtbk53g
22
- JFicdXEoDwwSH1cfHOMt94oDYk8bd17VRWWVl0yNB8b3dJwnZB63fNEJItC/f3nl
23
- TS9iIGgUFCTOuPAK36+ibGqPxz0CAwEAAaOBijCBhzAJBgNVHRMEAjAAMAsGA1Ud
24
- DwQEAwIEsDAdBgNVHQ4EFgQUQunHeoGoIoYOcBq6sJ7U7WmMxCcwJgYDVR0RBB8w
18
+ ggEBANMzRKAQ4QqtTKx2Tzu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lz5vMFzoZ/aLaytEaRxqMGkPieSwH3Z5
28
+ NpLGgyMyk3AneVN1JPtYExGfLYakVJ+x50rizAZirYdVBINTi44M1ZkuQGvFmldp
29
+ 89PRQvVuvpuYtAz0R94jC4zV3aC044vElu4FDMeMZRKBus4EFfaijZd7kPqRlzpa
30
+ uRCZ4WsmyKOap1NS0U7ZiXnJRvo0O5iptjFcbl/3rSTSRCIof+a35uCJppcSjhGZ
31
+ HGsLe8SKG8DXaaZxtrfB5toes3L8kzgWrblCbrvE10LDGRcRXwMSshNtb9iyK1mh
32
+ pR4QFidc/b8Rlw==
33
33
  -----END CERTIFICATE-----
34
- date: 2017-01-04 00:00:00.000000000 Z
34
+ date: 2017-09-06 00:00:00.000000000 Z
35
35
  dependencies: []
36
36
  description:
37
37
  email: james@jamesrobertson.eu
metadata.gz.sig CHANGED
Binary file