markdown-tables 0.0.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/markdown-tables.rb +11 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10ffe7f2352e6dce04a280d07a27c968f36a87ea
|
4
|
+
data.tar.gz: 128eb02c4f699e226b248957eebc260535290228
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78e9d514b7afbb39198c30e60ff2b9ccdcaefcda66b7d48096f5dd1e0c99c6315406e931f3f82178b4aa60e8383eb03c44be6d2da397f9f4d6c7e22e14c56157
|
7
|
+
data.tar.gz: 82f332402510d361145cbef7200a3e709dc94d1c04e3a9243b3fb20a9b7c6c91bea3591cd6052361275b1f121905f896f502ed232d407f4734f549912c4aecd0
|
data/lib/markdown-tables.rb
CHANGED
@@ -36,9 +36,16 @@ class MarkdownTables
|
|
36
36
|
# Convert a Markdown table into human-readable form.
|
37
37
|
def self.plain_text(md_table)
|
38
38
|
lines = md_table.split("\n")
|
39
|
-
labels = lines[0].split('|')
|
40
39
|
alignments = lines[1].split('|')
|
40
|
+
table_width = alignments.length
|
41
|
+
|
42
|
+
# Add back any any missing empty cells.
|
43
|
+
labels = lines[0].split('|')
|
44
|
+
labels.length < table_width && labels += [' '] * (table_width - labels.length)
|
41
45
|
rows = lines[2..-1].map {|line| line.split('|')}
|
46
|
+
rows.each_index do |i|
|
47
|
+
rows[i].length < table_width && rows[i] += [' '] * (table_width - rows[i].length)
|
48
|
+
end
|
42
49
|
|
43
50
|
# Replace non-breaking HTML characters with their plaintext counterparts.
|
44
51
|
rows.each do |row|
|
@@ -90,13 +97,11 @@ class MarkdownTables
|
|
90
97
|
# Sanity checks for make_table.
|
91
98
|
private_class_method def self.validate(labels, data, align, is_rows)
|
92
99
|
if labels.class != Array
|
93
|
-
raise('labels must be an
|
100
|
+
raise('labels must be an array')
|
94
101
|
elsif data.class != Array || data.any? {|datum| datum.class != Array}
|
95
102
|
raise('data must be a two-dimensional array')
|
96
103
|
elsif labels.empty?
|
97
104
|
raise('No column labels given')
|
98
|
-
elsif data.empty?
|
99
|
-
raise('No columns given')
|
100
105
|
elsif data.all? {|datum| datum.empty?}
|
101
106
|
raise('No cells given')
|
102
107
|
elsif labels.any? {|label| !label.respond_to?(:to_s)}
|
@@ -104,9 +109,9 @@ class MarkdownTables
|
|
104
109
|
elsif data.any? {|datum| datum.any? {|cell| !cell.respond_to?(:to_s)}}
|
105
110
|
raise('One or more cells cannot be made into a string')
|
106
111
|
elsif ![String, Array].include?(align.class)
|
107
|
-
raise('align must be a
|
112
|
+
raise('align must be a string or array')
|
108
113
|
elsif align.class == Array && align.any? {|val| val.class != String}
|
109
|
-
raise('One or more align values is not a
|
114
|
+
raise('One or more align values is not a string')
|
110
115
|
elsif !is_rows && data.length > labels.length
|
111
116
|
raise('Too many data columns given')
|
112
117
|
elsif is_rows && data.any? {|row| row.length > labels.length}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: markdown-tables
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris de Graaf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: chrisadegraaf@gmail.com
|
@@ -40,5 +40,5 @@ rubyforge_project:
|
|
40
40
|
rubygems_version: 2.6.8
|
41
41
|
signing_key:
|
42
42
|
specification_version: 4
|
43
|
-
summary: Utilities for creating and displaying Markdown tables in Ruby
|
43
|
+
summary: Utilities for creating and displaying Markdown tables in Ruby
|
44
44
|
test_files: []
|