texttable 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/texttable.rb +17 -7
- data/texttable.gemspec +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c035cbbcd41305294dd4118ac345509de89a5705d40c4051cc3e788ea208a5e
|
4
|
+
data.tar.gz: 6af6f4624fc36ff624a9f98d19919e177bef5686b87c139d360a7f84c6514451
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ed008e7c217c7c7ae9b90b5f2ff1716816a25240c35279a5aea92e92b96414eb75274ffb28efa8afd9815f57fa487d0d6c57484f1d03f4c366801c44ba9e515
|
7
|
+
data.tar.gz: 4a618de33a78ab41386f5ac8ec7f4f68781c8601b83ef694d9f55644a6e2089bfce821f67570036354b101f0d1b3448f6341380d28bb032e52ab3824da1c7a03
|
data/lib/texttable.rb
CHANGED
@@ -1,12 +1,19 @@
|
|
1
1
|
class TextTable
|
2
2
|
attr_accessor :values, :rows
|
3
3
|
|
4
|
-
def initialize(
|
4
|
+
def initialize(*args)
|
5
|
+
if args[0].is_a?(Array)
|
6
|
+
cols, *rows = args
|
7
|
+
rows = rows[0] if rows[0].is_a?(Array)
|
8
|
+
else
|
9
|
+
cols = args
|
10
|
+
rows = []
|
11
|
+
end
|
5
12
|
@cols = Hash.new {|h,k| h[k] = h.size}
|
6
|
-
@rows = rows
|
13
|
+
@rows = rows
|
7
14
|
@values = nil
|
8
15
|
@row = 0
|
9
|
-
cols.each {|col| index!(col) }
|
16
|
+
cols.each {|col| index!(col) }
|
10
17
|
end
|
11
18
|
|
12
19
|
def index(field, auto=false)
|
@@ -26,9 +33,11 @@ class TextTable
|
|
26
33
|
end
|
27
34
|
|
28
35
|
def convert_key(key)
|
29
|
-
key.
|
30
|
-
|
31
|
-
|
36
|
+
key.
|
37
|
+
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
|
38
|
+
gsub(/([a-z\d])([A-Z])/, '\1_\2').
|
39
|
+
gsub(/\W/, '_').
|
40
|
+
downcase
|
32
41
|
end
|
33
42
|
|
34
43
|
def size
|
@@ -83,7 +92,8 @@ class TextTable
|
|
83
92
|
value
|
84
93
|
end
|
85
94
|
|
86
|
-
def add(obj)
|
95
|
+
def add(obj, *args)
|
96
|
+
obj = [obj, *args] if args.size > 0
|
87
97
|
@values = @rows[@row = @rows.size] = []
|
88
98
|
case obj
|
89
99
|
when Hash then obj.each {|k, v| @values[@cols[k]] = v}
|
data/texttable.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: texttable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steve Shreeve
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: This gem will auto-size based on column widths.
|
14
14
|
email: steve.shreeve@gmail.com
|